Arthor
Arthor

Reputation: 674

AskForFolderName and check if folder Exists in .bat

I have this piece of code which I made some time ago. It is a simple check to prompt the user to put in a different name if the folder name exists. For some reason it does not work. If the folder exists it should Goto AskForFolderName. I cannot figure it out.

@echo off
@setlocal enableextensions enabledelayedexpansion
mode 90,10
color a

::Stage 3 - Check Folder
    :AskForFolderName

    set /p NewFolder=What is the name of the iteam being sold? 
    If ["%NewFolder%"]==[] Goto AskForFolderName
    If Exist "%NewFolder%" (
       Echo Folder already exists
       Echo.
       Goto AskForFolderName
    )


    Mkdir "003 - Images Ready\%NewFolder%"
    Move "002 - Process Images\"*.* "003 - Images Ready\%NewFolder%"
    ping 127.0.0.1 -n 20 > nul
    exit

Upvotes: 0

Views: 77

Answers (1)

user6811411
user6811411

Reputation:

Try this:

@echo off & setlocal enableextensions enabledelayedexpansion
mode 90,10
color a

::Stage 3 - Check Folder
:AskForFolderName

set /p "NewFolder=What is the name of the iteam being sold? "
If "%NewFolder%"=="" Goto :AskForFolderName
If Exist "003 - Images Ready\%NewFolder%\" (
   Echo Folder already exists
   Echo.
   Goto AskForFolderName
)

Mkdir "003 - Images Ready\%NewFolder%" 
Move  "002 - Process Images\*.*" "003 - Images Ready\%NewFolder%"
Timeout /NoBreak /T 20 > nul
exit

Upvotes: 1

Related Questions