mardi 28 avril 2015

Batch files: If directory exists, do something

I'm trying to do the following:

IF EXISTS ("C:\Users\user\Desktop\folder1\") {

MOVE "C:\Users\user\Desktop\folder2\" "C:\Users\user\Desktop\folder1\"
RENAME "C:\Users\user\Desktop\folder1\folder2\" "folder3"

} else {

MKDIR "C:\Users\user\Desktop\folder1\"
MOVE "C:\Users\user\Desktop\folder2\" "C:\Users\user\Desktop\folder1\"
RENAME "C:\Users\user\Desktop\folder1\folder2\" "folder3"

}

With the following code:

@ECHO OFF

FOR /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" SET "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%" SET "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

SET "date=%DD%%MM%%YY%"

IF EXIST "C:\Users\user\Desktop\folder1\" (GOTO MOVER)

PRINT "It doesn't exists" PAUSE

:MOVER PRINT "MOVER" PAUSE EXIT :END

But the system does not print the test words.

Aucun commentaire:

Enregistrer un commentaire