| 1. |
Solve : Batch remove - and . fixed length many suffix? |
|
Answer» I have to rename thousands of ???files with the nonstandard characters "." and "-". Fixed length, nothing else in folder, only the number changes, same DATE & system per folder, can be folder specificic, and multiple suffix, ie: Do you think the FOR loop is appropriate for this? Thanks. Absolutely. What I would do is enable delayed expansion and in a loop, READ in each filename, then using the ~n and ~x variable modifiers, split it into base name and extension, take the base name and use string replace (twice, once to replace . with _ and again to replace - with _) then add the extension back and use the old name and new name in a REN command. Unfortunately it is 7 AM here and I am gong to work so I won't be able to actually post some example code until around 9 hours time. Maybe somebody else will beat me to the punch? (Not you, Bill!) Quote from: Salmon Trout Maybe somebody else will beat me to the punch? Nobody would dare!!! Ugh, I don't know why the little smiley faces showed up all over my post! Thanks, Salmon Trout, that is the solution. I actually posted the same question on another forum and code using the filename parameter extensions (ie, %~n and %~a) were used in an FOR loop. I'll have to brush up on the use of extensions. I give credit to Salmon Trout and the other person with code for the solution. I'd post the other person's website and username, but I don't know how kosher that is with you all or him/her. Either way, you all have created a true believer in DOS-Batch. Thanks again.Code: [Select]@echo off setlocal enabledelayedexpansion for /f "delims=" %%A in ( ' dir /b ' ) do ( set oldbasename=%%~nA set extension=%%~xA set newbasename=!oldbasename:.=_! set newbasename=!newbasename:-=_! echo Renaming "!oldbasename!!extension!" to "!newbasename!!extension!" REN "!oldbasename!!extension!" "!newbasename!!extension!" ) echo. echo All done pause Quote from: AndrewJW on June 13, 2011, 08:22:54 AM I don't know why the little smiley faces showed up all over my post! Unless you show text as code, this forum shows VARIOUS character combinations as EMOTICONS to all guests and all registered users who have not have selected "No Smileys" as the "Current Smiley Set" in their Profile Look and Layout Preferences. These are 3 question marks: If you see that as that *censored* stupid bewildered emoticon, that is why. This is a figure 8 and an end bracket I really hate emoticons. |
|