0 votes

Is it possible to locate all file names containing %20 and change %20 to a space character, all from within File Locator Pro?

In the process of initially copying a folder to OneDrive for Business it couldn't sync a bunch of files that have %20 within the file name, which apparently is pretty common when you drag the URL open in a browser to a folder. This hasn't caused a problem when copying these same files between folders or to other drives, so it's a surprise.

Same problem with occurrences of # character in a file name.

asked by (30 points)

1 Answer

0 votes

You can easily find the files with %20 in the file name just search for that sequence, e.g.

File name:        %20
Containing text:
Look in:          E:\

Automatically replacing is a little more difficult. Using the XSL Transform below you can generate a batch file to rename each file, removing the %20.

Save the transform below to a file, e.g. rename_file.xsl, and then follow the steps in this QA article to apply the transform to your results and create a text file that can be used as a batch rename script.

<?xml version="1.0"?>
<!-- Rename a file to remove %20 from name

     Copyright (C) Mythicsoft Ltd 2015. All rights reserved.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

  <xsl:output method="text" indent="yes"/>

  <xsl:param name="replace-text">%20</xsl:param>

  <xsl:template match="/">
    <xsl:apply-templates select="//rslt:file"/>

  <!-- Rename command -->

  <xsl:template match="rslt:file">
    <xsl:value-of select="rslt:path"/>
    <xsl:value-of select="rslt:name"/>

    <xsl:call-template name="string-replace-all">
      <xsl:with-param name="text" select="rslt:name" />
      <xsl:with-param name="replace" select="$replace-text" />
      <xsl:with-param name="by">
        <xsl:text>&#32;</xsl:text>        <!-- Replace with space -->

    <xsl:text>"&#13;&#10;</xsl:text>      <!-- CR LF end of line -->

  <xsl:template name="string-replace-all">
    <xsl:param name="text" />
    <xsl:param name="replace" />
    <xsl:param name="by" />
      <xsl:when test="contains($text, $replace)">
        <xsl:value-of select="substring-before($text,$replace)" />
        <xsl:value-of select="$by" />
        <xsl:call-template name="string-replace-all">
          <xsl:with-param name="text"
          select="substring-after($text,$replace)" />
          <xsl:with-param name="replace" select="$replace" />
          <xsl:with-param name="by" select="$by" />
        <xsl:value-of select="$text" />


It should produce something like this:

ren "E:\test%20file%20With%20Spaces - Copy.htm" "test file With Spaces - Copy.htm"
ren "E:\test%20file%20With%20Spaces.htm" "test file With Spaces.htm"
answered by (56.8k points)
edited by