# Renaming files with %20 in the name

**URL:** <https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683>\
**Category:** Factual Questions\
**Created:** [May 29, 2004, 5:50pm UTC](https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683 "2004-05-29T17:50:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dewey\_Finn](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dewey_finn/32/4222_2.png) [@Dewey\_Finn](https://boards.straightdope.com/u/Dewey_Finn)\
**Post date:** [May 29, 2004, 5:50pm UTC](https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683/1 "2004-05-29T17:50:32Z")

</div>

I’ve got about fifteen files with %20 in the filename that I want to rename, ideally to replace the %20 with an actual space. (This is on Windows XP.) I’ve found previous threads on the subject of batch renaming where various utilities were recommended, but I’ve been trying to do this using the Windows rename command in a simple batch file. But Windows XP seemed to ignore the %20 when I created a batch file like this:

ren “file%20a01.txt” “file a01.txt”  
ren “file%20a02.txt” “file a02.txt”  
[et cetera]

Again, I’m aware that there are utilities that will make this simple, but just for my own education, can it be done without using one?

---

<div class="post-metadata">

**Author:** ![Bill\_H](https://avatars.discourse-cdn.com/v4/letter/b/a5b964/32.png) [@Bill\_H](https://boards.straightdope.com/u/Bill_H)\
**Post date:** [May 29, 2004, 5:54pm UTC](https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683/2 "2004-05-29T17:54:13Z")

</div>

As there’s only 15, I’d open an exporer window, select the file, press F2 (for rename), then manually rename them as you like.

Well, actually, I’d use cygwin, but that’s overkill if you don’t already have it.

---

<div class="post-metadata">

**Author:** ![Dewey\_Finn](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dewey_finn/32/4222_2.png) [@Dewey\_Finn](https://boards.straightdope.com/u/Dewey_Finn)\
**Post date:** [May 29, 2004, 5:59pm UTC](https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683/3 "2004-05-29T17:59:09Z")

</div>

> [@Bill H.](#):
>
> As there’s only 15, I’d open an exporer window, select the file, press F2 (for rename), then manually rename them as you like.
> 
> Well, actually, I’d use cygwin, but that’s overkill if you don’t already have it.

Thank you, but as I said, this is more about trying to figure this out. I’ve already spent more time trying to do it in a batch file than it would take to do it manually, but I find this sort of thing interesting.

---

<div class="post-metadata">

**Author:** ![SpaceDog](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/spacedog/32/9932_2.png) [@SpaceDog](https://boards.straightdope.com/u/SpaceDog)\
**Post date:** [May 29, 2004, 6:04pm UTC](https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683/4 "2004-05-29T18:04:51Z")

</div>

Explorer can be snarky for files it doesn’t like.

I can’t test this at the moment I’m guessing you need to escape some of the characters but try changing to the directory the files are in and starting off typing

ren file

and hit tab, it should complete the file name and properly escape the chars. Then fill in the rest of the command.

You can then either copy the format windows used or repeat the process (hiting tab multiple times cycles through the matching filenames).

It should be possible from the command line. My only other option is that it doesn’t like the file names (because at some level they’re equivalent). So you could try changing to an intermediate filename and then renaming that, I’ve used that in the past when windows acts up.

SD

---

<div class="post-metadata">

**Author:** ![ParentalAdvisory](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@ParentalAdvisory](https://boards.straightdope.com/u/ParentalAdvisory)\
**Post date:** [May 29, 2004, 6:20pm UTC](https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683/5 "2004-05-29T18:20:20Z")

</div>

ren file%%20a01.txt file\_a01.txt  
ren file%%20a02.txt file\_a02.txt

I had to add an underscore because the syntax was incorrect with the spaces in “file a01.txt”

---

<div class="post-metadata">

**Author:** ![ParentalAdvisory](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@ParentalAdvisory](https://boards.straightdope.com/u/ParentalAdvisory)\
**Post date:** [May 29, 2004, 6:28pm UTC](https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683/6 "2004-05-29T18:28:54Z")

</div>

The reason it didn’t work is because the command interpreter recognizes the percent symbol as the beginning of a variable and tries to match it to the variable table.

When you type ‘set’ at the command prompt you’ll get a list of set variables, heres a cut from mine:

SMS\_LOCAL\_DIR=C:\WINNT  
SystemDrive=C:  
SystemManufacturer=IBM  
SystemRoot=C:\WINNT

* * *

So if I typed ‘dir %SystemRoot%’, it would give me a directory listing of ‘C:\WINNT’, because %SystemRoot% is a variable matched to ‘C:\WINNT’. Just in case you didn’t know.

---

<div class="post-metadata">

**Author:** ![ParentalAdvisory](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@ParentalAdvisory](https://boards.straightdope.com/u/ParentalAdvisory)\
**Post date:** [May 29, 2004, 6:33pm UTC](https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683/7 "2004-05-29T18:33:48Z")

</div>

:smack:

Ok, the space in the file works now with the quotes, just gotta add that extra ‘%’:

ren “file%%20a01.txt” “file a01.txt”  
ren “file%%20a02.txt” “file a02.txt”

---

<div class="post-metadata">

**Author:** ![Dewey\_Finn](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dewey_finn/32/4222_2.png) [@Dewey\_Finn](https://boards.straightdope.com/u/Dewey_Finn)\
**Post date:** [May 29, 2004, 7:21pm UTC](https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683/8 "2004-05-29T19:21:10Z")

</div>

> [@ParentalAdvisory](#):
>
> Sometimes I’m obsessed.

Thank you. That worked perfectly. And I know exactly how you feel.

---

<div class="post-metadata">

**Author:** ![Bill\_H](https://avatars.discourse-cdn.com/v4/letter/b/a5b964/32.png) [@Bill\_H](https://boards.straightdope.com/u/Bill_H)\
**Post date:** [May 29, 2004, 7:50pm UTC](https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683/9 "2004-05-29T19:50:13Z")

</div>

**Dewey Finn** wrote

> [@](#):
>
> Thank you, but as I said, this is more about trying to figure this out. I’ve already spent more time trying to do it in a batch file than it would take to do it manually, but I find this sort of thing interesting.

As you find this sort of thing interesting, you may find cygwin interesting. It’s not a file-renaming utility. Rather, it’s like having a unix command prompt on a pc. (technically, it’s the bash shell on Windows.) If you like doing things at the command line (as do I as well), and you like making batch files to solve these sorts of problems, I highly recommend you check it out.

---

<div class="post-metadata">

**Author:** ![Dewey\_Finn](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dewey_finn/32/4222_2.png) [@Dewey\_Finn](https://boards.straightdope.com/u/Dewey_Finn)\
**Post date:** [May 29, 2004, 9:29pm UTC](https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683/10 "2004-05-29T21:29:33Z")

</div>

> [@Bill H.](#):
>
> As you find this sort of thing interesting, you may find cygwin interesting. It’s not a file-renaming utility. Rather, it’s like having a unix command prompt on a pc. (technically, it’s the bash shell on Windows.) If you like doing things at the command line (as do I as well), and you like making batch files to solve these sorts of problems, I highly recommend you check it out.

Thank you. I’ll look into it.

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [May 29, 2004, 10:18pm UTC](https://boards.straightdope.com/t/renaming-files-with-20-in-the-name/247683/11 "2004-05-29T22:18:03Z")

</div>

I’ll second Cygwin. Moving from DOS BATCH to bash is like going from a Yugo to a Corvette, and if you have any inclinations of learning another language bash shares the same basic structure as 90% of all modern language.

Does Cygwin include any POSIX libraries, or is it merely the shell and the GNU command-line utilities? It’s been years since I used it to work around the bug that is Windows 95.
