diff --git a/apps/files/templates/part.breadcrumb.php b/apps/files/templates/part.breadcrumb.php
index 9886b42e42463f5b34057ebb9677831bbdcceb50..9db27eb9b2935a8282b87efbb75a4f7c6f25cc90 100644
--- a/apps/files/templates/part.breadcrumb.php
+++ b/apps/files/templates/part.breadcrumb.php
@@ -7,8 +7,7 @@
 <?php endif;?>
 <?php for($i=0; $i<count($_["breadcrumb"]); $i++):
 	$crumb = $_["breadcrumb"][$i];
-	$dir = str_replace('+', '%20', urlencode($crumb["dir"]));
-	$dir = str_replace('%2F', '/', $dir); ?>
+	$dir = \OCP\Util::encodePath($crumb["dir"]); ?>
 	<div class="crumb <?php if($i == count($_["breadcrumb"])-1) p('last');?> svg"
 		 data-dir='<?php p($dir);?>'>
 	<a href="<?php p($_['baseURL'].$dir); ?>"><?php p($crumb["name"]); ?></a>
diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php
index 502ddd329b101b12e2b1d35ebc5514cd48c1bd66..97a9026860bc9ed87d085f1417d3ed247c0cfed6 100644
--- a/apps/files/templates/part.list.php
+++ b/apps/files/templates/part.list.php
@@ -17,10 +17,8 @@ $totalsize = 0; ?>
 	// the older the file, the brighter the shade of grey; days*14
 	$relative_date_color = round((time()-$file['mtime'])/60/60/24*14);
 	if($relative_date_color>160) $relative_date_color = 160;
-	$name = rawurlencode($file['name']);
-	$name = str_replace('%2F', '/', $name);
-	$directory = rawurlencode($file['directory']);
-	$directory = str_replace('%2F', '/', $directory); ?>
+	$name = \OCP\Util::encodePath($file['name']);
+	$directory = \OCP\Util::encodePath($file['directory']); ?>
 	<tr data-id="<?php p($file['fileid']); ?>"
 		data-file="<?php p($name);?>"
 		data-type="<?php ($file['type'] == 'dir')?p('dir'):p('file')?>"
diff --git a/apps/files_trashbin/templates/part.breadcrumb.php b/apps/files_trashbin/templates/part.breadcrumb.php
index 2801e04e9ad9d5fc1ad15d77cbe4f1fbf62064d7..85bb16ffa2d2822a90d3d9e315e45256ce9680f0 100644
--- a/apps/files_trashbin/templates/part.breadcrumb.php
+++ b/apps/files_trashbin/templates/part.breadcrumb.php
@@ -11,8 +11,7 @@
 <?php endif;?>
 <?php for($i=0; $i<count($_["breadcrumb"]); $i++):
 	$crumb = $_["breadcrumb"][$i];
-	$dir = str_replace('+', '%20', urlencode($crumb["dir"]));
-	$dir = str_replace('%2F', '/', $dir); ?>
+	$dir = \OCP\Util::encodePath($crumb["dir"]); ?>
 	<div class="crumb <?php if($i == count($_["breadcrumb"])-1) p('last');?> svg"
 		 data-dir='<?php p($dir);?>'>
 	<a href="<?php p($_['baseURL'].$dir); ?>"><?php p($crumb["name"]); ?></a>
diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php
index 92a38bd26350ce2bca8c382eba06fa8db05372a8..94a8eec9515669533f9846edb6c77b6bd3c98ef2 100644
--- a/apps/files_trashbin/templates/part.list.php
+++ b/apps/files_trashbin/templates/part.list.php
@@ -4,10 +4,8 @@
 	// the older the file, the brighter the shade of grey; days*14
 	$relative_date_color = round((time()-$file['date'])/60/60/24*14);
 	if($relative_date_color>200) $relative_date_color = 200;
-	$name = str_replace('+', '%20', urlencode($file['name']));
-	$name = str_replace('%2F', '/', $name);
-	$directory = str_replace('+', '%20', urlencode($file['directory']));
-	$directory = str_replace('%2F', '/', $directory); ?>
+	$name = \OCP\Util::encodePath($file['name']);
+	$directory = \OCP\Util::encodePath($file['directory']); ?>
 	<tr data-filename="<?php p($file['name']);?>"
 		data-type="<?php ($file['type'] == 'dir')?p('dir'):p('file')?>"
 		data-mime="<?php p($file['mimetype'])?>"