Batch renaming files


Joined
Apr 5, 2018
Messages
29
Reaction score
0
I have written a "*.BAT" file to rename some files.
I need to rename a bunch of files every now and then and it is a tedious task to rename them 1 by 1.
In the older DOS days, this batch file would run without problems.
But in Windows "Command Prompt" I keep getting an error.
What is wrong with the batch file?
TIA

Example:
newname.bat
rename e:\pictures\sorted\2003\20030106 ?144326 carmen.jpg e:\pictures\sorted\2003\20030106 144326 carmen.jpg
rename e:\pictures\sorted\2003\20030106 ??144740 carmen.jpg e:\pictures\sorted\2003\20030106 144740 carmen.jpg
rename e:\pictures\sorted\2003\?20030106 ??144810 carmen.jpg e:\pictures\sorted\2003\20030106 144810 carmen.jpg
rename e:\pictures\sorted\2003\?20030106 ??144811 carmen.jpg e:\pictures\sorted\2003\20030106 144811 carmen.jpg
rename e:\pictures\sorted\2003\?20030106 ??144832 carmen.jpg e:\pictures\sorted\2003\20030106 144832 carmen.jpg

REMARK:

The Question Mark in the first files is the Hex Character "3F" which doesn't appear in Windows but does appear in some File Renaming Applications and in the Command Prompt.
 
Last edited:
Ad

Advertisements

Joined
Mar 20, 2016
Messages
14
Reaction score
4
If that is the actual bat file you're using the command wrong. The second part should just be the filename, not the whole path.

If that's the output, maybe that ? char is not passing the parsing in the command.
 
Joined
Apr 5, 2018
Messages
29
Reaction score
0
If that is the actual bat file you're using the command wrong. The second part should just be the filename, not the whole path.

Even trying the same batch file with your suggestion does not work.

If that's the output, maybe that ? char is not passing the parsing in the command.

The character "3F (?)" in the Batch seems to confuse Windows.
 
Joined
Feb 22, 2014
Messages
1,612
Reaction score
335
Are you using quotes? The full path name that includes spaces will need to be enclosed in quotes. Spaces will split the path into multiple parameters causing errors.

rename "e:\pictures\sorted\2003\?20030106 ??144832 carmen.jpg" "e:\pictures\sorted\2003\20030106 144832 carmen.jpg"
 
Joined
Apr 5, 2018
Messages
29
Reaction score
0
Are you using quotes? The full path name that includes spaces will need to be enclosed in quotes. Spaces will split the path into multiple parameters causing errors.

rename "e:\pictures\sorted\2003\?20030106 ??144832 carmen.jpg" "e:\pictures\sorted\2003\20030106 144832 carmen.jpg"
Tried that already without success.

As a tip for everyone who send an answer to this thread I advise to try to run the batchfile on their PC and see if it works before sending an answer (replace the "?" by character 3F).
 
Joined
Feb 22, 2014
Messages
1,612
Reaction score
335
Now that I think about it. I think I ran into issues before when including the path in the destination parameter. The destination only needs a name to change the file to. After all the file is being renamed not moved.

rename "e:\pictures\sorted\2003\?20030106 ??144832 carmen.jpg" "20030106 144832 carmen.jpg"
 
Ad

Advertisements

Joined
Apr 5, 2018
Messages
29
Reaction score
0
Now that I think about it. I think I ran into issues before when including the path in the destination parameter. The destination only needs a name to change the file to. After all the file is being renamed not moved.

rename "e:\pictures\sorted\2003\?20030106 ??144832 carmen.jpg" "20030106 144832 carmen.jpg"
A "more elaborate" answer:

The primary filename "?20030106 ??144832 carmen.jpg" has the character 3F ("?") in the filename.
If I look up for the file in Windows Explorer or most Windows utilities, the file will be displayed as "20030106 144832 carmen.jpg".
The character 3F will be omitted.
Something similar is happening when running the Batch file with the Command prompt and Windows will not find the PRIMARY file.
Windows Powershell see the PRIMARY file WITH THE CHARACTER 3F and doesnt seem to have the same restrictions of the Command prompt, but Powershell uses a complete different way to program a Batch file (read "*.cmd") file which I don't fully master.
Does this answer your input in this thread?
 
Ad

Advertisements

Joined
Feb 22, 2014
Messages
1,612
Reaction score
335
Someone else will need to help you fix your UI. I don't use Explorer. Never have and never will. I can help you with your command-line script. Which is what I thought you were asking for. Sorry, my mistake.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top