| 1. |
Solve : ren command with wild cards? |
|
Answer» I am trying to rename multiple files in a folder, APPENDING a text to the end of each filename. for example, I am using the following ren command to rename 4 files, but it only renames 2 files correctly, says :"A duplicate file name exists" error for the 1 file: Just out of curiosity, why does the single line rename command (in my first post) mess up the file names? Thanks! The wildcard you used results in two files getting the same new name, so the second one causes an error, and is skipped. Study these and you will see how the wildcard works 1. SalesDigest_Atlanta.pdf becomes SalesDigest_new.pdf 2. SalesDigest_Atlanta_Reg.pdf becomes SalesDigest_Atlanta_new.pdf 3. SalesDigest_Natl.pdf becomes SalesDigest_new.pdf (this already exists because it was used at step 1) 4. SalesDigest_Natl_Trad.pdf becomes SalesDigest_Natl_new.pdf The syntax is ren [Drive:][PATH] filename1 filename2. You can use wildcards (* and ?) in either file name parameter. If you use wildcards in filename2, the characters represented by the wildcards will be identical to the corresponding characters in filename1. Expanding slightly, the syntax is ren file1 file2. In your ren command: file1 is *.* which means 'process every file'. file2 is *_new.* which is the specification for the new name and is interpreted as "everything in the original name up to the last underscore, followed by _new. followed by everything after the last dot in the original name" This means that these two original file names would get the same new name. SalesDigest_Atlanta.pdf - > SalesDigest_new.pdf SalesDigest_Natl.pdf -> SalesDigest_new.pdf The original name that sorts earliest is processed first, and gets the new name. The second one causes a name collision and is skipped with this error message sent to the console: C:\>ren *.* *_new.* A duplicate file name exists, or the file cannot be found. If anyone is interested, there is a good summary on Superuser http://superuser.com/questions/475874/how-does-the-windows-rename-command-interpret-wildcards |
|