Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Ok, here's one for you. I'm trying to use a batch file to rename a bunch of files, but none of them are in the same folder as the batch file itself. The command prompt keeps telling me that the directory can't be found. I suppose I could just rename all the files in all the folders that match the filename, but I don't want to do that either; I only want to change certain ones.

My batch file as it stands is:

@echo off
ren "engine/info.txt" "disabled.txt"
ren "gravplating/info.txt" "disabled.txt"
ren "HAWX content/info.txt" "disabled.txt"
ren "laserz/info.txt" "disabled.txt"
ren "NeuroNaval/info.txt" "disabled.txt"
ren "NeuroPlanes/info.txt" "disabled.txt"
ren "NeuroTanks/info.txt" "disabled.txt"
ren "NeuroWeapons/info.txt" "disabled.txt"
ren "WAC Base/info.txt" "disabled.txt"
ren "WAC DamageSystem/info.txt" "disabled.txt"
ren "WAC GravityController/info.txt" "disabled.txt"
ren "WAC Helicopters/info.txt" "disabled.txt"
ren "WAC Sweps/info.txt" "disabled.txt"
ren "weapons/info.txt" "disabled.txt"
ren "AFF_ships/info.txt" "disabled.txt"
ren "AntiTakeRifle/info.txt" "disabled.txt"
ren "Catmull-Rom Cameras/info.txt" "disabled.txt"
ren "Displacer Cannon/info.txt" "disabled.txt"
ren "Drumdevil's Trains/info.txt" "disabled.txt"
ren "EVEOnline/info.txt" "disabled.txt"
ren "gm_botmap_v3/info.txt" "disabled.txt"
ren "gm_construct_flatgrass_v5-2/info.txt" "disabled.txt"
ren "gm_mobenix_v3_final/info.txt" "disabled.txt"
ren "gm_mobenix_v3_highquality_Water/info.txt" "disabled.txt"
ren "gm_snabbansairfield_b1/info.txt" "disabled.txt"
ren "gm_XhS_construct/info.txt" "disabled.txt"
ren "linedraw/info.txt" "disabled.txt"
ren "ModelManipulator/info.txt" "disabled.txt"
ren "NeuroCars/info.txt" "disabled.txt"
ren "Propeller Engine/info.txt" "disabled.txt"
ren "VanDookie and Predaaator's pack/info.txt" "disabled.txt"
ren "WAC ECM/info.txt" "disabled.txt"
ren "WAC Extra Helicopters/info.txt" "disabled.txt"
echo Done!
pause
share|improve this question

1 Answer 1

Two things you need to consider:

  1. You should use backslash () to separate between path parts parts, not forward slash (/).

  2. It is assumed that all the directories you specified are located in the same directory as your script, and that your run your script from the same location as the directories.

So, I recommend correcting it as follows:

rem CD to the directory in which this script is located:
CD "%~dp0"

rem 'Use' '/', not '\'
ren "gravplating\info.txt" "disabled.txt"
ren "HAWX content\info.txt" "disabled.txt"
ren "laserz\info.txt" "disabled.txt"

rem [...]
share|improve this answer
    
Unless the questioner is using one of the DOSes, which is unlikely given the use of non-8.3 filenames there, the use of forward slash as a pathname component separator is perfectly fine. It is explicitly supported in pathnames by at least one operating system that "batch files" could run on — the very operating system that you are assuming with that CD command, in fact. And since the command arguments are all quoted and not absolute pathnames, there isn't the concern that it might be confused with a command option, either. –  JdeBP Nov 17 '11 at 10:51
    
JdeBP, I am not sure what you mean. I don't know how to write multi-line comments here, so please read this: pastebin.com/DkdnVwMs. –  Yonatan Orlev Nov 17 '11 at 12:47
    
Erm...huh? I'm not entirely sure I understand... –  Carnaxus Nov 18 '11 at 8:08
    
There are a few lines in my answer. Tell me exactly what you don't understand. BTW, anybody knows how can I be notified by email on comments as well as answers to a given post? –  Yonatan Orlev Nov 20 '11 at 9:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.