| 1. |
Solve : "For" and "If" command doubt? |
|
Answer» Hi, I just ran your script twice, and the first time, it renamed "0D0A inside.jpg" to "Front Cover Inside.jpg", and added this line to log.txt My problem is when "Front Cover Inside.jpg" coexists with some file like "0D0A inside.jpg". What I want to be logged is: Code: [Select]"Similar file to "S:\Test\Batch\After 03-07-2010\for-if\0D0A inside.jpg" already exists" which in this case is "Front Cover Inside.jpg"). Then, after reading the log, I will manually check which file is "0D0A inside.jpg" and if it's quality is better than "Front Cover Inside.jpg" it will delete this one. I need this because I have thousands of album art files I don't want to check then one by one... TIAFinally I think I've solved my problem. My final batch looks like this: Quote echo off The trick is using errorlevel. When trying to rename the file, if there's already a file with the same name, MS-DOS will return a error message. I've just use this to sove my problem. I've tried different scenarios and it worked the way I want it. So, I'm proud of myself, considering how newbie I'm in MS-DOS command line... Quote from: vitorb on September 11, 2010, 07:40:29 AM Finally I think I've solved my problem. My final batch looks like this: This is going to start driving me completely INSANE. Quote from: BC_Programmer on September 11, 2010, 08:33:52 AM
Sorry... You're completely right! I know that MS-DOS it's a operating system and what I'm using is just a command line interpreter. Ten YEARS ago I USED MS-DOS for a few months, but I never developed any SKILLS on it's usage...And the tweaking goes on... My previous batch had one problem. This code: Code: [Select]for /R %%x in (*inside.jpg) do if not exist "Front Cover Inside.jpg"doesn't seems to work correctly because after the batch finish I saw that every "Front Cover Inside.jpg" files in various directories had been renamed again to it's current name. Code: [Select]ren "%%x" "Front Cover Inside.jpg"Whenever %x is "Front Cover Inside.jpg" it will be: Code: [Select]ren "Front Cover Inside.jpg" "Front Cover Inside.jpg" which is useless... So I've change it this way: Code: [Select]for /R %%x in (*inside.jpg) do if "%%~nxx"=="Front Cover Inside.jpg" ( echo "Front Cover Inside.jpg" already exists ) else ( ren "%%x" "Front Cover Inside.jpg" if errorlevel 1 ( echo Similar file to "%%x" already exists >> Log.txt ) else ( echo "%%x" renomed to "Front Cover Inside.jpg" >> Log.txt ) ) |
|