![]() If "%file:~-1%"=" " (set "file=%file:~0,-1%" Microsoft included a batch rename feature in the latest version of Windows allowing you to select multiple files, right click on one and select rename. If "%file:~0,1%"=" " (set "file=%file:~1%" How to make a batch file to rename a folder when I start a program - Let's say I want to start my word.exe, at the same time I need to rename a folder c:\users\my profile\my word documents to be my documents and when I exist the word.exe the batch rename the folder to its original name. If you really only want filenames starting with string1 to be renamed, remember to delete the first asterisk in the pattern specified in string3.įOR /F "tokens=* USEBACKQ" %%F IN (`dir "%dir%\%str3%" /a:-d /b /s /-p`) DO (call:rename_sub "%%F") Delete the echo before the ren command once you've satisfied yourself that it does what you want. "simple-1simple-2" to be renamed as "aa1aa2".ĭo not use "s in setting any of the variables aside from the ones already there.īy default it only echoes the rename commands but without actually performing them. Note again, this will replace ALL instances of string1 with string2, so do not use if you wouldn't want, for e.g. (This can happen if, for example, you use this code to convert underscores or dashes to spaces and the original filename began with one). It will search for all filenames matching the pattern specified in string3, then replace all occurrences of string1 with string2 in those filenames.Īs a bonus it will perform a safety check to ensure that the proposed new filename doesn't start or end with a space or a dot, and will trim them off before the rename. You just need to enter the four variables at the start. Below is a Batch File adapted from code I have previously written on Win10. >"%~dp0temp.txt" echo %Prefixo%%APZ%%~x1 %~1 %Prefixo%%AP%%~x1Įcho This Folder doesn't exist! "%Pasta%"Įcho "%~1" -^> "%~n2 %~x2">"%~dp0rename.log"Īnother possible option. I have a batch file I use to rename files with the date and time stamp: RENAME W:TEST. Set /p "Prefixo=%BS% Please set a prefix: " ![]() ![]() If not exist "%Pasta%\" goto :PastaInexistente ![]() If exist "%~1" (if exist "%~1\" set "Pasta=%~1") else (set /p "Pasta=%BS% Please Inform the Folder: ") For /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a" ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |