File Rename not working as desired

November 27, 2011 at 10:42:17
Specs: Windows XP
I want to rename file "I G_0009.JPG" to 9.JPG. Why is the following command not working?
Rename "I G_000?.JPG" "?.JPG"
-Bibhuti

See More: File Rename not working as desired

Report •

#1
November 27, 2011 at 11:27:03
I assume you mean from a command prompt?

If so you will need to direct the path to the folder containing the jpg file.

The syntax I would normally use for that particular file is:
Ren "I G_0009.JPG" "9.JPG" so the syntax including the path would be:

Ren "C:\top folder\sub folder\I G_0009.JPG" "9.JPG"

Another way is to run the short expression as a batch file from within the folder containing "I G_0009.JPG". That way eliminates the need for stating the path.

Always pop back and let us know the outcome - thanks


Report •

#2
November 28, 2011 at 09:41:25
Derek,
Sorry I did not say what the problem was. The problem was not it not finding the directory. It found it correctly, but changed it to wrong name. It changed it to I.JPG. I expected to take 9 into ? and change it to 9.JPG as ? is in that position in the first file name. I want to change a bunch of files in one shot-
I G_0009.JPG to 9.JPG
I G_0008.JPG to 8.JPG
I G_0007.JPG to 7.JPG
Could you say what the command should be. I have tried using * aswell. It resulted in the same.
Thanks.
-Bibhuti

Report •

#3
November 28, 2011 at 09:59:47
Question mark is not a valid character in Windows so it will be rejected in any file or folder name.

Always pop back and let us know the outcome - thanks


Report •

Related Solutions

#4
November 28, 2011 at 10:14:58
The use of * and ? is illustrated in many examples given by many on REN. So I am not sure why it will be rejected. It is not rejecting it, but behavior is different from what I expected. It's taking the first char of the file name rather than the position where it is.

What is the solution??


Report •

#5
November 28, 2011 at 11:16:01
OK, understood.

Seems you need a more expert response so I'll leave it to others.


Report •

#6
December 1, 2011 at 07:32:48
If you're wondering why no one is particularly interested in responding, it's because this has been asked before, and we've apparently gotten bored with the answer.

Derek: Question mark is not a valid character
This is because it's a wild card character, used in the DOS days when you wanted to manipulate a lot (read: more than one) of files at a time.

BibhutiPatel: behavior is different from what I expected.
Sadly, REN's handling of the wild card characters is bad. It's either buggy, or so unintuitive it might as well be buggy.

Untested script:

setlocal EnableDelayedExpansion
for %%a in ("I G_000?.JPG") do (
  set name=%%~Na
  ren "%%a" "!name:~-1!%%~Xa"
)

How To Ask Questions The Smart Way


Report •

#7
December 1, 2011 at 13:46:43
Razor2.3

Yep, I'd misunderstood and thought poster was trying to produce files with question mark in them. Ooops, obviously getting rusty on DOS LOL.

Always pop back and let us know the outcome - thanks


Report •

Ask Question