DOS question
-
I have to rename in some folders many file. The file are named like:
L1.txt
L2.txt
...
L9.txt
L10.txt
...
L99.txt
L100.txt
...Now, to apply some code, I need that the names changes to
L001.txt
...
L009.txt
L010.txt
...
L099.txt
L100.txtI was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like
rename L?.txt L00?.txt
rename L??.txt L0??.txtbut it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)
Russell
Flash Renamer - http://www.rlvision.com/downloads.asp[^]
Melting Away www.deals-house.com www.innovative--concepts.com
-
I have to rename in some folders many file. The file are named like:
L1.txt
L2.txt
...
L9.txt
L10.txt
...
L99.txt
L100.txt
...Now, to apply some code, I need that the names changes to
L001.txt
...
L009.txt
L010.txt
...
L099.txt
L100.txtI was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like
rename L?.txt L00?.txt
rename L??.txt L0??.txtbut it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)
Russell
Kind of old school, but for tasks like this, I'll fire up my spreadsheet program of choice and build individual statements using simple formulas and cell formatting. Once you have a column of commands, you can copy them and paste them into the command prompt and they'll run one at a time. Not as cool as PowerShell or some of the other better answers, but it gets the job done.
Joe Enos joe@jtenos.com
-
Kind of old school, but for tasks like this, I'll fire up my spreadsheet program of choice and build individual statements using simple formulas and cell formatting. Once you have a column of commands, you can copy them and paste them into the command prompt and they'll run one at a time. Not as cool as PowerShell or some of the other better answers, but it gets the job done.
Joe Enos joe@jtenos.com
Joe has the best answer on this one.
-
I have to rename in some folders many file. The file are named like:
L1.txt
L2.txt
...
L9.txt
L10.txt
...
L99.txt
L100.txt
...Now, to apply some code, I need that the names changes to
L001.txt
...
L009.txt
L010.txt
...
L099.txt
L100.txtI was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like
rename L?.txt L00?.txt
rename L??.txt L0??.txtbut it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)
Russell
Hmm, multiple tools available really, depending on budget and the amount of effort you want to use: ZTREE (remember Xtree for DOS), ZTree is based on this, is still being developed and sold, and has none of the memory limits of the old DOS Xtree, seing as how its a Windows 32bit console app. Otherwise look at XXCOPY if you want something that runs in a window, DirectoryOpus or Powerdesk for native windows GUI. If you want 'free', then Powershell would be a good start, or one of the many 'Norton Commander' clones out there.
-
I have to rename in some folders many file. The file are named like:
L1.txt
L2.txt
...
L9.txt
L10.txt
...
L99.txt
L100.txt
...Now, to apply some code, I need that the names changes to
L001.txt
...
L009.txt
L010.txt
...
L099.txt
L100.txtI was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like
rename L?.txt L00?.txt
rename L??.txt L0??.txtbut it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)
Russell
Use the following script. It does the following: For each *.txt file in the current directory... 1. remove the first character, assuming it is an L 2. add 00 to the front 3. extracts the last 7 characters XXX.txt, where XXX is the original number padded with zeros 4. adds the L back to the front 5. does the rename
@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=" %%a in ('dir /b *.txt') do (
(set i=%%a)
(set i=00!i:~1,100!)
(set i=L!i:~-7!)
echo rename "%%a" to "!i!"
rename "%%a" "!i!"
)
endlocal -
Bingo! :) When I first saw (Windows a.k.a.) Total Commander, I used to sneer at it. But that was a long time ago. Now, I never look at whatsitcalled included with windows.
..................... Life is too shor
At least, I think that's what it does, so surely they named it that. Same initials, anyway. Total Commander is da bomb, baby. Select the files (or folders) to rename, press CTRL-M for the rename dialog, and bask in the options. Also note the preview before committing changes.
Narf.
-
Joe has the best answer on this one.
-
Use the following script. It does the following: For each *.txt file in the current directory... 1. remove the first character, assuming it is an L 2. add 00 to the front 3. extracts the last 7 characters XXX.txt, where XXX is the original number padded with zeros 4. adds the L back to the front 5. does the rename
@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=" %%a in ('dir /b *.txt') do (
(set i=%%a)
(set i=00!i:~1,100!)
(set i=L!i:~-7!)
echo rename "%%a" to "!i!"
rename "%%a" "!i!"
)
endlocalI like that!
-
I have to rename in some folders many file. The file are named like:
L1.txt
L2.txt
...
L9.txt
L10.txt
...
L99.txt
L100.txt
...Now, to apply some code, I need that the names changes to
L001.txt
...
L009.txt
L010.txt
...
L099.txt
L100.txtI was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like
rename L?.txt L00?.txt
rename L??.txt L0??.txtbut it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)
Russell
-
Hmm, multiple tools available really, depending on budget and the amount of effort you want to use: ZTREE (remember Xtree for DOS), ZTree is based on this, is still being developed and sold, and has none of the memory limits of the old DOS Xtree, seing as how its a Windows 32bit console app. Otherwise look at XXCOPY if you want something that runs in a window, DirectoryOpus or Powerdesk for native windows GUI. If you want 'free', then Powershell would be a good start, or one of the many 'Norton Commander' clones out there.
Mike is right, for jobs like these I can't live without ZTree. You can insert, delete portions of the name, insert an autoincrement (with or without the leading zeroes), etc.
-
I have to rename in some folders many file. The file are named like:
L1.txt
L2.txt
...
L9.txt
L10.txt
...
L99.txt
L100.txt
...Now, to apply some code, I need that the names changes to
L001.txt
...
L009.txt
L010.txt
...
L099.txt
L100.txtI was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like
rename L?.txt L00?.txt
rename L??.txt L0??.txtbut it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)
Russell
I use either Stexbar[^] or Shell Renamer[^]
-
I have to rename in some folders many file. The file are named like:
L1.txt
L2.txt
...
L9.txt
L10.txt
...
L99.txt
L100.txt
...Now, to apply some code, I need that the names changes to
L001.txt
...
L009.txt
L010.txt
...
L099.txt
L100.txtI was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like
rename L?.txt L00?.txt
rename L??.txt L0??.txtbut it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)
Russell
for /I %I in (1,1,9) do ren L%I.txt L00%I.txt
for /I %I in (10,1,99) do ren L%I.txt L0%I.txtSoftware Zen:
delete this;
-
I have to rename in some folders many file. The file are named like:
L1.txt
L2.txt
...
L9.txt
L10.txt
...
L99.txt
L100.txt
...Now, to apply some code, I need that the names changes to
L001.txt
...
L009.txt
L010.txt
...
L099.txt
L100.txtI was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like
rename L?.txt L00?.txt
rename L??.txt L0??.txtbut it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)
Russell
Up till a couple of months ago I would have written this in VBScript no sweat but these days I am writing everything in PowerShell to get my skills up. Thanks for the challenge.
# Make 100 test files (create dir structure first)
1..100 | % ($_){New-Item "c:\scripts\Lfiles\L$_.txt" -type file}# Rename all files to specification (remove -whatif switch to make it live)
Get-ChildItem c:\scripts\Lfiles | % ($_){rename-item -path $_.fullname -newname (($_.basename -replace "[0-9]", "")+("{0:000}" -f [int]($_.basename -replace "[^0-9]", ""))+($_.extension)) -whatif} -
I think the best way to do this is to use a batch file and the FOR command. Take a look at this[^] for some ideas.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
Assuming Russell is actually using DOS (we still have machinery running DOS exclusively on 386 and 486 machines), I think Henry's idea is probably the best place to start. The DOS ? and * wildcard characters don't always give exactly the expected results.
-
I have to rename in some folders many file. The file are named like:
L1.txt
L2.txt
...
L9.txt
L10.txt
...
L99.txt
L100.txt
...Now, to apply some code, I need that the names changes to
L001.txt
...
L009.txt
L010.txt
...
L099.txt
L100.txtI was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like
rename L?.txt L00?.txt
rename L??.txt L0??.txtbut it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)
Russell
For files with numbers less than 10: FOR /L %F in (1,1,9) DO REN L%F.txt L00%F.txt For files with numbers from 10 to 99: FOR /L %F IN (10,1,99) DO REN L%F.txt L0%F.txt You could expand this out with a check to make sure the file exists: FOR /L %F IN (1,1,9 DO IF EXIST L%F.txt REN L%F.txt L00%F.txt
-
I have to rename in some folders many file. The file are named like:
L1.txt
L2.txt
...
L9.txt
L10.txt
...
L99.txt
L100.txt
...Now, to apply some code, I need that the names changes to
L001.txt
...
L009.txt
L010.txt
...
L099.txt
L100.txtI was thinking to use the old DOS. I was hoping to use a couple of command to solve the problem. Something like
rename L?.txt L00?.txt
rename L??.txt L0??.txtbut it looks to not work as desired. I think it understands the 'input' names, but wrong to interpret the second string of the command. any expert on the 'old' DOS? :)
Russell
Whenever I have to do bulk renaming I always include DOS in the mix... First I place all the files in c:\work folder entering the following in DOS C: CD C:\WORK DIR /B > FILES.TXT yields a simple text file with all file names listed one per line. then make a second copy of the TXT file COPY FILES.TXT FILES1.TXT FILES.TXT becomes the rename "Command" portion and FILES1.TXT becomes the "New Names" portion of the exercise. Many times the file names I am converting contain spaces so that means the RENAME command requires the name be encased in quotes. so using a text editor (I use JSoft's EditPadPro) I do a search and replace of carriage returns... FIND [CR] and REPLACE WITH: " RENAME " This puts a quote at the end of each line and the rename command-space-quote at the beginning of each line (with manual tweaking of the first and last lines). Save FILES.TXT Open FILES1.TXT in the text editor and with some thoughtful and creative "String Search and Replace" convert this list into the required filenames. Using the Block Mode Selection feature, copy this column of file names. Open FILES.TXT and paste this block into the far right field of the first row (making sure the block does not crash into the existing text.) Save FILES.TXT I then open FILES.TXT in CuteHTML because it has a "Code Optimizer" feature that allows me to remove all extra spaces from the file. Save the FILES.TXT as FILES.BAT Back in DOS run FILES and WOOSH!... easy-peasy. The whole process usually goes pretty quickly and is the best way I have found to deal with insanely punctuated filenames. I know this is nowhere near as elegant as you where hoping for but that is what I would be doing. change L to L00, change L001 to L1 to get the hundreds and manually fix L1.txt to L001.txt and on like that. more power to you!
-
For files with numbers less than 10: FOR /L %F in (1,1,9) DO REN L%F.txt L00%F.txt For files with numbers from 10 to 99: FOR /L %F IN (10,1,99) DO REN L%F.txt L0%F.txt You could expand this out with a check to make sure the file exists: FOR /L %F IN (1,1,9 DO IF EXIST L%F.txt REN L%F.txt L00%F.txt
that was what I was looking for! thank you -------------------------------------------------------------------- If someone in future will have the same problem I also report here a more complex script I prepared before reading this reply that does the same thing (I hope :~). Because for me it is trivial to not change absolutely the name of the files, then the script is very robust on this feature (and it display a sort of report to check all the progress) Thanks again to all
@echo off
@echo File 001 to 009
set /a cnt1=1
:DATA0109
IF NOT EXIST L%cnt1%.sg2 @echo L%cnt1%.sg2 not found
IF EXIST L%cnt1%.sg2 @echo rename L%cnt1%.sg2 L00%cnt1%.sg2
IF EXIST L%cnt1%.sg2 rename L%cnt1%.sg2 L00%cnt1%.sg2
set /a cnt1+=1
if %cnt1%==10 goto :DATA1099BEGIN
goto :DATA0109:DATA1099BEGIN
@echo File 010 to 099
set /a cnt1=0
set /a cnt2=1
:DATA1099
IF NOT EXIST L%cnt2%%cnt1%.sg2 @echo L%cnt2%%cnt1%.sg2 not found
IF EXIST L%cnt2%%cnt1%.sg2 @echo rename L%cnt2%%cnt1%.sg2 L0%cnt2%%cnt1%.sg2
IF EXIST L%cnt2%%cnt1%.sg2 rename L%cnt2%%cnt1%.sg2 L0%cnt2%%cnt1%.sg2
set /a cnt1+=1
if %cnt1%==10 set /a cnt2+=1
if %cnt1%==10 set /a cnt1=0
if %cnt2%==10 goto :EXIT
goto :DATA1099:EXIT
pause
goto :EOF
Russell
-
For files with numbers less than 10: FOR /L %F in (1,1,9) DO REN L%F.txt L00%F.txt For files with numbers from 10 to 99: FOR /L %F IN (10,1,99) DO REN L%F.txt L0%F.txt You could expand this out with a check to make sure the file exists: FOR /L %F IN (1,1,9 DO IF EXIST L%F.txt REN L%F.txt L00%F.txt
Gotta LOVE that FOR-IN-DO!! L_O_
VE This Suggestion! -
+1 for BRU! It works great. :)
There are some really weird people on this planet - MIM.
BRU has been solid and great for years. You have to upgrade to use it across a network, though.