Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Batch file to rename without spaces
Name: WeaselNo7 Date: October 7, 2004 at 07:41:38 Pacific OS: XP Home SP2 CPU/Ram: P4/512Mb
Comment:
Ello!
Am wondering if you guys can help... I've managed pieces of this problems, but not the whole thing...
I need to make a batch script that renames all files in a given folder (passed at param to script, folders can have spaces in the names!), so that the files have any spaces in the names replaced with underscores.
Problems I came across: -I don't want to rename the directories the files are in too! -Files can have multiple spaces in the names. -Files can have multiple CONSECUTIVE spaces in the names.
Name: IVO Date: October 7, 2004 at 08:33:55 Pacific
Reply:
No trickies... only a good knowledge of NT scripting
@Echo Off
Set Folder=%* For /F "tokens=*" %%A in ('Dir "%*" /B /A-D') Do Call :REN %%A Set File= Set FileNew= GoTo :EOF
:REN Set File=%* Set FileNew=%File: =_% If not "%File%"=="%FileNew%" Ren "%Folder%\%*" "%FileNew%" GoTo :EOF
Note: For /F....Call :REN %%A fits just one line of code.
Save as XRen.bat then type Xren Folder_Name, e.g. XRen My Folder with Files and you are done ("My Folder with Files" is a folder name that holds spaces)
0
Response Number 2
Name: WeaselNo7 Date: October 8, 2004 at 07:24:11 Pacific
Reply:
That's bloody elegant! Nice work IVO!
0
Response Number 3
Name: Terry.Webb Date: November 11, 2004 at 08:24:27 Pacific
Reply:
Hi, Also wanted something similar, however the %* parameter prefixes the parameters with a "space", which confuses the script (invalid directory and file names) - Using NT4.0 SP6.
Summary: I need a batch file to rename the contents of a directory and then move the file to another directory (archive). The format of the files are 123456.edi and they need to be TCOL123456.edi. I've no expe...
Summary: SWEET! I used your code from sept07 and modified it but I need help debugging it. It renamed 1i "Address" to "Email" but it did not complete the data transfer...see below: ~~~~~~~~~~~~~~~~~~~~~~~ ne...
Summary: I have a program that creates daily log files that are a lot larger than I would like them to be. I would like to have this so there would be 3 or 4 log files daily. The logs are named logMMDD.txt. I ...