1.

Solve : batch file for renaming existing folder?

Answer»

My requirement is : If folder is already exist then do not replace it and create new folder with siffix.

example: if i'm TRYING to move folder "64327". then first check whether folder already exist at destination or not , if it exist then create new folder with "64327_XXXXX".

How to acheive this. also how to check whether folder exist or not??

i need to do this in batch file. IF EXIST "C:\users\Squash\My Folder" md "C:\users\Squash\My Folder_XXXXX"Thanks, it is working. how to write else part, i tried


IF EXIST "C:\users\Squash\My Folder" md "C:\users\Squash\My Folder_XXXXX" else md "C:\users\Squash\My Folder"

but this is not working


i want to use this with robocopy, is it possible

currently i'm copy and replacing existing by below command
robocopy C:\Completed_Jobs\63k \\server1\63k /S /MOVE

but what i want is to copy first time and if exist then don't replace and create new folder with name "63K_XXXXXX"

PLEASE advise.Quote from: [emailprotected] on August 13, 2012, 02:25:01 PM

Thanks, it is working. how to write else part, i tried


IF EXIST "C:\users\Squash\My Folder" md "C:\users\Squash\My Folder_XXXXX" else md "C:\users\Squash\My Folder"

but this is not working
Code: [SELECT]IF EXIST "C:\users\Squash\My Folder" (
md "C:\users\Squash\My Folder_XXXXX"
) else (
md "C:\users\Squash\My Folder"
)not working.

for if section it says -- the syntax of command is incorrect

and for else section it says -- 'else' is not recognised as an external and internal command

please advise.You need the trailing \ to reliably test for folders, but the syntax looks fine and works fine here in Windows 7.

What OS are you using?

IF EXIST "C:\users\Squash\My Folder\" (
md "C:\users\Squash\My Folder_XXXXX"
) else (
md "C:\users\Squash\My Folder"
)

Forgive my INTRUSION, but wouldn't it save space to write:

Code: [Select]IF EXIST "C:\users\Squash\My Folder\" md "C:\users\Squash\My Folder_XXXXX"
IF NOT EXIST "C:\users\Squash\My Folder\ md "C:\users\Squash\My Folder"

That way you use 2 lines instead of 5. That is, unless there is a flaw in this method that I didn't see. Unless you plan on ADDING and rd to the if exist statement, which would require and else.I beat you with one line.

Code: [Select]IF EXIST "C:\users\Squash\My Folder\" (md "C:\users\Squash\My Folder_XXXXX") else (md "C:\users\Squash\My Folder")Quote from: foxidrive on August 14, 2012, 01:26:18 AM
I beat you with one line.

You also won in the character count event. However, the double-liner was easier to read. By the time I got to the end of the one-liner, I was gasping for air and forgotten how I got got there. Quote from: Sidewinder on August 14, 2012, 05:57:45 AM
You also won in the character count event. However, the double-liner was easier to read. By the time I got to the end of the one-liner, I was gasping for air and forgotten how I got got there.
Which is why I break it up. Easier to read.This is shorter, and a single line, even with a couple of whitespace characters.

Code: [Select]MD "C:\users\Squash\My Folder\" 2>nul || md "C:\users\Squash\My Folder_XXXXX"Quote from: foxidrive on August 14, 2012, 06:42:03 PM
This is shorter, and a single line, even with a couple of whitespace characters.

Code: [Select]MD "C:\users\Squash\My Folder\" 2>nul || md "C:\users\Squash\My Folder_XXXXX"
Me likey!
Conditional Operators are one of my favorite things about batch


Discussion

No Comment Found