windows - How to test if a file is a directory in a batch script? -
is there way find out if file directory?
i have file name in variable. in perl can this:
if(-d $var) { print "it's directory\n" }
you can so:
if exist %var%\nul echo it's directory
however, works directories without spaces in names. when add quotes round variable handle spaces stop working. handle directories spaces, convert filename short 8.3 format follows:
for %%i in (%var%) if exist %%~si\nul echo it's directory
the %%~si
converts %%i
8.3 filename. see other tricks can perform for
variables enter help for
@ command prompt.
(note - example given above in format work in batch file. work on command line, replace %%
%
in both places.)
Comments
Post a Comment