Batch Determine if input is a file or folder?

July 29, 2011 at 10:02:03
Specs: Windows 7
I am currently trying to make a batch program that asks the user to input either a file name, location, or a 'reference' file (a text file that lists multiple locations) and copy all the files inside that, onto a folder onto the desktop, and then rename them to include the date. I almost have everything done, but i am wondering, how would i write a short script to determine if the user had typed a folder, or filename?

See More: Batch Determine if input is a file or folder?

Report •

#1
July 29, 2011 at 13:27:30
Lacking any clever answers. . .
DIR "%somePath%" >NUL 2>&1
IF ERRORLEVEL 1 (@ECHO Not a valid file/dir &GOTO end)
DIR "%somePath%" /AD >NUL 2>&1
IF ERRORLEVEL 1 (@ECHO A file &GOTO end)
@ECHO A Directory 
:end

How To Ask Questions The Smart Way


Report •

#2
July 29, 2011 at 13:35:26
ok, i put this after my set /p somepath= Type the file or directory

after i type a folder that i know i have in the directory, it closes right away. did i copy it wrong?


Report •

#3
July 29, 2011 at 14:07:05
Don't know. Either force the Command Prompt window to stay open by adding a PAUSE command, or run the batch script from the command line.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
August 2, 2011 at 07:49:39
oh, nevermind, i got it to work. Thanks a lot!!

Report •

Ask Question