| 1. |
Solve : MS-DOS rename? |
|
Answer» I'm trying to rename many similar file names at once. @echo off & setlocal enabledelayedexpansion In trying to understand the code this is my understanding: @echo off & setlocal enabledelayedexpansion COMMANDS NOT DISPLAYED TO SCREEN & PERFORM COMMANDS LOCALLY (CURRENT DIRECTORY ONLY?) for %%a in ("CND_m2_*.SHT") do ( ==FOR %variable IN (set) DO command [command-parameters]== FINDS WHERE THE FILENAME = “CND_m2_*.SHT” (NAMED VARIABLE A) set f=%%~na set f=!f:CND_m2_=! CREATES SET OF FILES TO PERFORM COMMAND TO (SET NAMED “CND_m2_*.SHT”) ren "%%~nxa" "!f!.DGN" RENAME ) What am I missing or doing wrong? Thankshere's a vbscript alternative Code: [Select] Set objFS = CREATEOBJECT("Scripting.FileSystemObject") strFolder = "c:\test" Set objFolder = objFS.GetFolder(strFolder) For Each strFile In objFolder.Files strFileName = strFile.Name If InStr(strFileName,"CND_m2") > 0 Then strFileName = Replace(strFileName,"CND_m2_","") strFileName = Replace(strFileName,"_WORKING.SHT","") strNewName = strFileName & ".DGN" strFile.Name= strNewName End If Next save as myscript.vbs and on command prompt, Code: [Select]c:\test> cscritp /nologo myscript.vbs 1. put the batch file inside the same folder as .SHT files 2. start-->run-->type cmd then enter 3. cd to the directory where the .SHT files eg. cd c:\test\ 4. type batchfile.bat at cmd prompt or rename the batch file to cmd extension and double-click to runQuote I tried this as a batch (stored in the same folder as the files) and the cmd window flashed on & off but nothing happened. I opened a cmd window and pasted and got this:I clicked the bat which makes sense now why pops up run and closes a command window, but when I pasted the command after changing directory (cd) to the folder containing the files i want to change, is when i got the errorThanks gh0std0g74 Yes! That removed the beginning part, but only added .dgn to the end. In the cmd window Quote ren *_working.sht.dgn *.dgndoesn't make any changes either. But, Quote ren ??_working.sht.dgn ??.dgnchanges the filename correctly. Is there a way to WRITE the script character specific (quantity wise)?Quote from: fsjeep on May 13, 2009, 07:42:01 PM I'm trying to rename many similar file names at once.Code: [Select]@echo off & setlocal enabledelayedexpansion pushd c:\workingshitfolder\ && ( for %%a in ("CND_m2_*.SHT") do ( set f=%%~na set f=!f:CND_m2_=! set f=!f:_WORKING=! set f=!f:~,6!!f:~7,1!!f:~6,1!!f:~8,99! echo "%%~nxa" --^> "!f!.DGN" ren "%%~nxa" "!f!.DGN" ) popd ) || echo invalid folder pause example output: Code: [Select]D:\batch>dir/b cnd* CND_m2_CND-7130-01_WORKING.SHT D:\batch>sht "CND_m2_CND-7130-01_WORKING.SHT" --> "CND-7103-01.DGN" Press any key to continue . . . D:\batch>dir/b cnd* CND-7103-01.DGNThanks Reno! that last one works awesome!! |
|