| 1. |
Solve : Replacing characters in a large amount of folders? |
|
Answer» Hi, what's all that weird euro language stuff? I 'm sorry, I forgot to paste only the relevant part, edited the code now "Er zijn 1 map(pen) verplaatst." means 1 folder has been moved.An alternative, maybe: if you want to take folder names containing # and replace that character with _ why bother using move? Just get the folder name into a string variable, use the replace function of the SET command, and rename the folder with the new string. E.g Code: [Select]echo off setlocal enabledelayedexpansion for /f "delims=" %%A in ('dir /b /ad *#*') do ( set oldname=%%A set newname=!oldname:#=_! echo renaming "!oldname!" to "!newname!" REN "!oldname!" "!newname!" ) To do all subdirectories change dir /b /ad to dir /s /b /ad Before... Code: [Select]C:\test>dir Volume in drive S is USBHD Volume Serial Number is 2C51-AA7F Directory of C:\Test 15/09/2010 08:45 PM <DIR> . 15/09/2010 08:45 PM <DIR> .. 15/09/2010 08:44 PM <DIR> folder#1 15/09/2010 08:44 PM <DIR> folder#2 15/09/2010 08:44 PM <DIR> folder#3 15/09/2010 08:44 PM <DIR> folder#4 15/09/2010 08:45 PM <DIR> folder#4#5#6#####7 15/09/2010 08:44 PM 215 test1.bat 1 File(s) 217 bytes 7 Dir(s) 188,506,218,496 bytes free Code: [Select]c:\Test\>test1.bat renaming "folder#1" to "folder_1" renaming "folder#2" to "folder_2" renaming "folder#3" to "folder_3" renaming "folder#4" to "folder_4" renaming "folder#4#5#6#####7" to "folder_4_5_6_____7" After... Code: [Select]C:\Test>dir Volume in drive S is USBHD Volume Serial Number is 2C51-AA7F Directory of C:\Test 15/09/2010 08:48 PM <DIR> . 15/09/2010 08:48 PM <DIR> .. 15/09/2010 08:44 PM <DIR> folder_1 15/09/2010 08:44 PM <DIR> folder_2 15/09/2010 08:44 PM <DIR> folder_3 15/09/2010 08:44 PM <DIR> folder_4 15/09/2010 08:45 PM <DIR> folder_4_5_6_____7 15/09/2010 08:48 PM 217 test1.bat 1 File(s) 217 bytes 7 Dir(s) 188,506,218,496 bytes free Indeed, this also works, but the effect is in this case exactly the sale with move as rename here? I'm not sure in win7 but I thought rename didn't work for folder in XP? Quote from: Jupke on September 15, 2010, 02:18:59 PM Indeed, this also works, but the effect is in this case exactly the sale with move as rename here? Yes, however move has a potential ambiguity that ren does not, viz: move folder1 folder2 (if folder2 does not exist!) is equivalent to ren folder1 folder2; BUT if folder2 does exist, folder1 can be moved to be a subfolder of folder2, unless its attributes forbid this . However, ren only renames, never MOVES. Quote I'm not sure in win7 but I thought rename didn't work for folder in XP? 1. Where did you get that idea? 2. Could you not have done an experiment? 3. It works for all Windows, as far as I know, as long as you have the right permissions and the folder attributes allow it. Code: [Select]G:\test>ver Microsoft Windows XP [Version 5.1.2600] G:\test>md testdir G:\test>dir Volume in drive G is DATA1 Volume Serial Number is 9476-662D Directory of G:\test 15/09/2010 22:42 <DIR> .. 15/09/2010 22:42 <DIR> testdir 15/09/2010 22:42 <DIR> . 0 File(s) 0 bytes 3 Dir(s) 16,695,369,728 bytes free G:\test>ren testdir cakes-and-coffee G:\test>dir Volume in drive G is DATA1 Volume Serial Number is 9476-662D Directory of G:\test 15/09/2010 22:42 <DIR> .. 15/09/2010 22:42 <DIR> cakes-and-coffee 15/09/2010 22:42 <DIR> . 0 File(s) 0 bytes 3 Dir(s) 16,695,369,728 bytes free G:\test> |
|