|
Answer» Hi There,
I am a content uploader for mobile phones. I need to format various content provided by the vendors to ours standard format. so, plz help me to rename multiple FOLDERS at one time to our desired format.
Example:
From Format 30x30png 40x30bmp 120x300_bmp BMP270x300
To Format png30x30 bmp40x30 bmp120x300 bmp270x300
Thanks!Hello, The problem you have PRESENTED can easily be done in a batch file. However, there is some information that you have not given. What assurance is there that these file names are unique and will not encounter duplication when they are converted? Here's why I ask. Programming involves more than just finding some code that takes care of a specific issue. Programming also involves foresight as to conflicts. Some mechanism is needed to guarantee the file names be unique. This leads to the prospect of using a different method rather than just changing names in batch files. Without knowing more about what kind of system you're using, there should be some kind of library, database or index is able to keep track of files and a sign them a suitable alias reusing your system. Imperatively changing a file name can have serious consequences. The so-called DOS environment does not have a recursive tracking the history of a file, such as who the author was, what its original name was and other information like that. If you're doing ANYTHING on a very large scale you should be using some kind of database or library system and not relying just on DOS. Okay. That is the end of my rant. I thought appropriate to say this because you indicate your going to be doing this over a large-scale and many other people would be affected by what you do. End of rant.
Somebody will come here and give you a neat clean solution to your problem using only DOS and no third-party programs.The folder names have no pattern, so writing a script would be problematic.
Folders 1 & 2: move three trailing characters to be three leading characters Folder 3: same as two above folders and eliminate the underscore Folder 4: Replace three leading uppercase characters with lowercase characters
The logic for folder 1,2,3 can be combined into a single script block. Folder 4 PRESENTS a problem. Not only will it require a separate script block, but there is no characteristic to key off of in order to determine when to activate that script block.
This little snippet will handle folders 1,2,3:
Code: [SELECT]@echo off setlocal enabledelayedexpansion
for /f "tokens=* delims=*" %%i in ('dir /b /ad') do ( set dirname=%%i set dirname1=!dirname:_=! set prefix=!dirname1:~-3! set suffix=!dirname1:~0,-3! ren !dirname! !prefix!!suffix! )
Path information is your responsibility. As for folder #4, converting uppercase to lowercase can be done, but as mentioned there is nothing inherent in the folder name to distinguish it from the other three.
Good luck.
I would humbly suggest brute force:
Code: [Select]@echo off ren 30x30png png30x30 ren 40x30bmp bmp40x30 ren 120x300_bmp bmp120x300 ren BMP270x300 bmp270x300
Hi Sidewinder/Geek-9pm,
I really appreciate your support for the scripts and about letting me know the scale of the problem.
Thanks! Sravan Hi,
Guys can we execute the script based on the idea..
(special character)(file type:png/bmp)(special character)[size](special character)(file type:png/bmp)(special character)
Special character= all wild characters like (.,_-$#@!%^&*..etc) Size=100x100, 200x100 ..etc file type: png/bmp Lower case letters. I'm just not getting it. The original solution was specific to the sample folder names you posted.
What is this? Quote (special character)(file type:png/bmp)(special character)[size](special character)(file type:png/bmp)(special character)
Depending on the language, special characters need to be escaped, or not, depending on their usage. You're creating unneeded problems.
Pattern matching and replacements can be accomplished by using regular expressions (RegEx). The RegEx engine in batch is next to useless, but VBScript, Powershell, Python, and Perl along with many UNIX utilities can handle most tasks. Is that a possibilty?
The easiest solution of course would be to tell your vendors what format to supply their content in.
Let use know. Hi,
Thanks for the advice..i won't be WORRYING any of us..will go with the brute force as you mentioned..its easy..and more over..i am new to programming and interested to write scripts..so i wish to try.. anyways will stay connected to learn.
Regards, Sravan Hello, I am also in the similar situation, trying to rename folders. I just need to get rid of "_den" suffix from folders' name. For e.g. I want to rename "Warde_den" to "Warde"; "Divide_NW_den" to "Divide_NW"; "Tripoli_NW_SE_den" to "Tripoli_NW_SE" etc...
Should be easy..but I am new to programming and need help.
Plz help..
Nav
|