DOS question
-
Write a program in your favorite language on any platform to generate a throw away batch file. Don't waste too much time messing with all of the DOS quirks. DONT FORGET TO LEAVE ROOM FOR EXPANSION! 110 files today is 100,000 files tomorrow! example in C int i; for (i = 1; i <= 100; ++i) printf("ren L%d.txt L%5.5d.txt\r\n"); capture the output via: a.exe > myrename.bat myrename.bat
-
FYI, I would do it like this (from the command prompt, not from a batch file): for %f in (1 2 3 4 5 6 7 8 9) do rename L%f.txt L00%f.txt for %f in (1 2 3 4 5 6 7 8 9) do for %g in (0 1 2 3 4 5 6 7 8 9) do rename L%f%g.txt L0%f%g.txt that would work to rename the 1-99 files. The 100 file is already in that format. Sincerely G
The code
NuLiFree wrote:
for %f in (1 2 3 4 5 6 7 8 9) do rename L%f.txt L00%f.txt for %f in (1 2 3 4 5 6 7 8 9) do for %g in (0 1 2 3 4 5 6 7 8 9) do rename L%f%g.txt L0%f%g.txt
does not cater for missing entries. You could add
2>nul
to the end of the renames to hide the errors, but the following (untested) would be safer and (in the second set) faster if some cases are not required:for %f in (1 2 3 4 5 6 7 8 9) do if exist L%f.txt rename L%f.txt L00%f.txt
for %f in (1 2 3 4 5 6 7 8 9) do if exist L%f?.txt for %g in (0 1 2 3 4 5 6 7 8 9) do if exist L%f%g.txt rename L%f%g.txt L0%f%g.txtYou might want to change the two occurrences of
(1 2 3 4 5 6 7 8 9)
to(0 1 2 3 4 5 6 7 8 9)
to catch some erroneously named files. -
I've used this before and I totally agree.