Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need to rename some files; they have periods in the filenames and this seems to fox ren.
I would like to rename files like
012_11.03.12.1ic_NCS_LI.jpg
002_11.03.12.1ba_ NS_LI.jpg012_11.03.12.1ic_LI.jpg
002_11.03.12.1ba_LI.jpgie remove the _NCS or _NS component
I've tried:
h:\test\????????????????*.jpg ????????????????_LI.jpgbut this truncates at the first . to
001_11_LI.jpg
002_11_LI.jpgam i right in thinking it's the periods which it doesn't like...and is there a smart solution?
Thanks in advance, Tom.

Sorry, double quotes make absolutely no difference?
Surely this must be possible?
....or maybe not!
*throws down a challenge*

Tom,
I'm almost sure it's possible.
And I'll bet IVO or jboy could do it in their sleep.
I'll work on it.
I got a right to be slow; I'm old.
M2

Well, I did not answer to the post as that is a NT question not a DOS one, but here is the solution and you have to thank Mechanix2Go if you get it.
Save the batch naming as you want and type
RPer Folder (I named it RPer - Folder is the folder storing the *.jpg)) and you are done.
@Echo Off
Set JDir=%*
For /F "tokens=*" %%A in ('Dir "%JDir%\*.jpg" /B') Do Call :REN %%A
Set JDir=
GoTo :EOF:REN
Set OldF=%*
Set NewF=%OldF:_NCS=%
If "%NewF%"=="%OldF%" Set NewF=%OldF:_NS=%
Ren "%JDir%\%OldF%" "%NewF%"
Set OldF=
Set NewF=
GoTo :EOF

Hi Mechanix2Go,
I'm not just a kid! I run my first program (a FORTRAN IV procedure simulating tankers refilling) on an IBM 7040 in 1972 as my assignment for the Operation Research class at University. That was the classical glass-room monster, a pre 360/370 computer era.
So try to compute my age, baby.
PS: that program never worked as planned.

Sorry to interupt the banter...
this is my first .bat (the first time is always the best) and I can't get it to work:
H:\>myren test
The system cannot find the file specified.both myren.bat and test file are in H:\>
Thanks, Tom.

Hi Tom,
is myren the batch I posted?. If yes, it is planned to process .jpg files. If none exists it returns an error message. So is test Directory storing .jpg files?

Tom.
Is 'test' the FOLDER?
IVO sez:
"(I named it RPer - Folder is the folder storing the *.jpg)"
As long as you're starting out, get used to the idea that as far as a command interpreter is concerned [be it DOS or NT / 2k /XP emulation] there are no folders. There are files, directories and not much else.
M2

Sorry to be back only now,
according to your post the trouble is related to the Ren statemant. As I tested the batch and it run fine on my system, please may you run the script coding an Echo before the Ren and report exactly what is displayed?.
I need your help to debug.

Both your .bat file and the suggestion of using double quotes for ren on the command line worked when I got home on XP. Clearly an NT problem.
As originally mentioned, perhaps this wasn't the right place to raise the issue!
incidently adding Echo before the ren command the .bat file provided again gives
C:\>myren test
The system cannot find the file specified.when both myren (the .bat) and test (containing the files) are in root.
Anyway, we got the job done...and many thanks OVM and M2 you have saved my colleagues many hours of tedious work.
And I'm no longer a .bat virgin!
Thanks, Tom.

Tom,
Glad it flew.
The rocket scientists's name is IVO. You can learn a lot by reading his msgs.
M2

A last note, even if we can never know the unknown:
the behavior of myren script should be invariant under NT. Actually I tested it under Win XP and 2000 where it worked fine. The same I supposed under NT, those systems all sharing the same kernel.
Microsoft OS are really an unended challenge!
PS for Mechanix2Go:
You was smart in computing my age, but I can't give you the reward (€ 1.000.000), as the correct response is 54.
Never mind, you lack some marginal data: in Italy a doctorate enginnering degree required at that time 5 years and I was late to face programming as I spent the first three years in the Nuclear Enginnerring course reverting to the Electrical one only the last two years.
Next time you'll be more lucky.

IVO,
I wish I was 54 again. In '72 I was majoring in girls an math.
Tom, you can perhaps appreciate why some here are sticklers for exact OS / conditions. One size does not fit all except in the most trivial BAT files.
M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |