92

Is there any way to find out if a file is a directory?

I have the file name in a variable. In Perl I can do this:

if(-d $var) { print "it's a directory\n" }
aschipfl
  • 33,626
  • 12
  • 54
  • 99
Vhaerun
  • 12,806
  • 16
  • 39
  • 38
  • Related: [How to test if a path is a file or directory in Windows batch file?](https://stackoverflow.com/q/8666225) – aschipfl Mar 13 '21 at 23:36

23 Answers23

109

This works:

if exist %1\* echo Directory

Works with directory names that contains spaces:

C:\>if exist "c:\Program Files\*" echo Directory
Directory

Note that the quotes are necessary if the directory contains spaces:

C:\>if exist c:\Program Files\* echo Directory

Can also be expressed as:

C:\>SET D="C:\Program Files"
C:\>if exist %D%\* echo Directory
Directory

This is safe to try at home, kids!

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Gerard
  • 1,359
  • 1
  • 9
  • 7
  • 5
    This seems to be good, it even correctly handles empty folder correctly. Update: doesn't seem to require the '*' either, just the '\' on the end seems to be enough to verify that it is a folder. – Grant Peters Jan 27 '11 at 00:06
  • 13
    Awesome, **this** even **works** with [Directory Links](http://stackoverflow.com/questions/138981/how-do-i-test-if-a-file-is-a-directory-in-a-batch-script#comment14656200_138995)! But **only with the `*`!!** (Also @GrantPeters) – Aaron Thoma Jun 23 '12 at 19:41
  • 7
    Just in case the quotes are a problem, this works too: if exist "%~1\" echo It's a directory – MarioVilas Jun 06 '13 at 14:10
  • 1
    This method does not work in Windows 10 20H2. – CoolCmd Apr 25 '21 at 17:05
  • Great! Works for me even with UNC paths and drive letters mapped to network shares. Previously I used just \ which works for local files and dirs. – GravityWell Mar 06 '22 at 14:29
  • @CoolCmd Tested working on 20H2 and 21H1. Did you forget the asterisk or quotes? – Wilderness Ranger Oct 24 '22 at 18:07
  • @WildernessRanger, do not remember how i tested. at least it fail when running from Far Manager prompt. – CoolCmd Oct 25 '22 at 20:00
71

Recently failed with different approaches from the above. Quite sure they worked in the past, maybe related to dfs here. Now using the files attributes and cut first char

@echo off
SETLOCAL ENABLEEXTENSIONS
set ATTR=%~a1
set DIRATTR=%ATTR:~0,1%
if /I "%DIRATTR%"=="d" echo %1 is a folder
:EOF
phuclv
  • 37,963
  • 15
  • 156
  • 475
batchman61
  • 719
  • 5
  • 2
  • 12
    This is totally the best answer here... It even works if you don't have read permissions on the target file or directory (which is exactly what I needed). Thanks! – ewall Jun 22 '11 at 14:53
  • 1
    One of three solutions on this page that works: isFile.bat example: http://pastebin.com/dmYKKa7M – Jakob Sternberg Jan 03 '14 at 04:51
  • 1
    Don't know why but my batch file does not expand `%1` to file/folder full path. I have to use `%~f1`. It expands paths like `.` and `..` to real path. – WesternGun Feb 08 '21 at 22:59
  • This is the best way because it uses documented features and therefore will work in future versions of Windows. For example, the method with most "likes" on this page does not work in Windows 10 20H2. But this one works. – CoolCmd Apr 25 '21 at 17:10
61

You can do it like so:

IF EXIST %VAR%\NUL ECHO It's a directory

However, this only works for directories without spaces in their names. When you add quotes round the variable to handle the spaces it will stop working. To handle directories with spaces, convert the filename to short 8.3 format as follows:

FOR %%i IN (%VAR%) DO IF EXIST %%~si\NUL ECHO It's a directory

The %%~si converts %%i to an 8.3 filename. To see all the other tricks you can perform with FOR variables enter HELP FOR at a command prompt.

(Note - the example given above is in the format to work in a batch file. To get it work on the command line, replace the %% with % in both places.)

Kevin Fegan
  • 1,292
  • 1
  • 16
  • 29
David Webb
  • 190,537
  • 57
  • 313
  • 299
  • you forgot the d flag i think – RomanM Sep 26 '08 at 12:05
  • It worked fine for me and what "D" flag? Roman - The "D:" in your answer is a reference the "D:" drive on your machine. Vhaerun - what did you have VAR set to when you tried this? – David Webb Sep 26 '08 at 13:04
  • C:\sdf>if exist filethatexists\nul @echo wontdisplayanything <-- try that, see here --> http://pastebin.com/raw.php?i=u8trFYLf – barlop Apr 07 '12 at 08:24
  • 10
    **THIS DOES NOT WORK** with [Directory Symbolic Links (Softlinks) or Junctions](http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html): Files whose path contains a Directory Link are misrecognized as Directory. To reproduce, type: `cmd` [++](http://blogs.msdn.com/b/tims/archive/2006/11/02/windows-vista-secret-10-open-an-elevated-command-prompt-in-six-keystrokes.aspx) `mklink /d LinkDir .` `cd LinkDir` `if exist regedt32.exe\nul echo File erroneously detected as Directory` `rd .` – Aaron Thoma Jun 23 '12 at 19:13
  • 9
    It doesn't work. However, adding a backslash at the end did work for me. For example: if exist "%~1\" echo It's a directory – MarioVilas Jun 06 '13 at 14:08
  • MarioVilas is right.. On Windows 7 at least "\NUL" doesn't work. but just "\" works! Thanks! – Dss Dec 06 '13 at 22:08
  • 2
    This works: FOR %%i IN (%1) DO IF EXIST %%~si\* ECHO IS FOLDER – Jakob Sternberg Jan 03 '14 at 04:16
  • 2
    This also doesn't work for UNC paths (i.e. \\server\share\...). @Vhaerun: Please update your "accepted answer" mark to batchman61's one - that is the only robust answer on this page – WinTakeAll Apr 15 '16 at 21:26
  • Checking with NUL doesn't work on ReactOS, but checking with "%var%\\*" does. – Ken Jackson Aug 11 '17 at 15:08
12

Further to my previous offering, I find this also works:

if exist %1\ echo Directory

No quotes around %1 are needed because the caller will supply them. This saves one entire keystroke over my answer of a year ago ;-)

Gerard
  • 1,359
  • 1
  • 9
  • 7
  • 7
    **THIS DOES NOT WORK** with [Directory Symbolic Links (Softlinks) or Junctions](http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html): Files whose path contains a Directory Link are misrecognized as Directory. To reproduce, type: `cmd` [++](http://blogs.msdn.com/b/tims/archive/2006/11/02/windows-vista-secret-10-open-an-elevated-command-prompt-in-six-keystrokes.aspx) `mklink /d LinkDir .` `cd LinkDir` `if exist regedt32.exe\ echo File erroneously detected as Directory` `rd .` – Aaron Thoma Jun 23 '12 at 19:44
11

Here's a script that uses FOR to build a fully qualified path, and then pushd to test whether the path is a directory. Notice how it works for paths with spaces, as well as network paths.

@echo off
if [%1]==[] goto usage

for /f "delims=" %%i in ("%~1") do set MYPATH="%%~fi"
pushd %MYPATH% 2>nul
if errorlevel 1 goto notdir
goto isdir

:notdir
echo not a directory
goto exit

:isdir
popd
echo is a directory
goto exit

:usage
echo Usage:  %0 DIRECTORY_TO_TEST

:exit

Sample output with the above saved as "isdir.bat":

C:\>isdir c:\Windows\system32
is a directory

C:\>isdir c:\Windows\system32\wow32.dll
not a directory

C:\>isdir c:\notadir
not a directory

C:\>isdir "C:\Documents and Settings"
is a directory

C:\>isdir \
is a directory

C:\>isdir \\ninja\SharedDocs\cpu-z
is a directory

C:\>isdir \\ninja\SharedDocs\cpu-z\cpuz.ini
not a directory
indiv
  • 17,306
  • 6
  • 61
  • 82
  • 3
    This works even with [Directory Symbolic Links (Softlinks) and Junctions](http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html). (As opposed to the `\NUL` and `\` techniques.) – Aaron Thoma Jun 28 '12 at 22:19
  • 1
    @accolade - what are the **\`\`** techniques ? – Kevin Fegan Jul 03 '16 at 16:47
  • 1
    @KevinFegan (It looks like StackExchange changed the parsing of `\`…\`` inline code formatting.) « `` » was supposed to be « ``\`` ». I was referring to the the approach of appending a backslash at the end of the filename, e.g. proposed here: http://stackoverflow.com/questions/138981/how-do-i-test-if-a-file-is-a-directory-in-a-batch-script/143935?noredirect=1#answer-3845794 – Aaron Thoma Dec 05 '16 at 10:59
6

This works perfectly

if exist "%~1\" echo Directory

we need to use %~1 to remove quotes from %1, and add a backslash at end. Then put thw whole into qutes again.

Aziz
  • 747
  • 2
  • 7
  • 12
  • 4
    **THIS DOES NOT WORK** with [Directory Symbolic Links (Softlinks) or Junctions](http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html): Files whose path contains a Directory Link are misrecognized as Directory. To reproduce, type: `cmd` [++](http://blogs.msdn.com/b/tims/archive/2006/11/02/windows-vista-secret-10-open-an-elevated-command-prompt-in-six-keystrokes.aspx) `mklink /d LinkDir .` `cd LinkDir` `if exist "regedt32.exe\" echo File erroneously detected as Directory` `rd .` – Aaron Thoma Jun 23 '12 at 19:48
4

A variation of @batchman61's approach (checking the Directory attribute).

This time I use an external 'find' command.

(Oh, and note the && trick. This is to avoid the long boring IF ERRORLEVEL syntax.)

@ECHO OFF
SETLOCAL EnableExtensions
ECHO.%~a1 | find "d" >NUL 2>NUL && (
    ECHO %1 is a directory
)

Outputs yes on:

  • Directories.
  • Directory symbolic links or junctions.
  • Broken directory symbolic links or junctions. (Doesn't try to resolve links.)
  • Directories which you have no read permission on (e.g. "C:\System Volume Information")
Explorer09
  • 569
  • 5
  • 9
4

CD returns an EXIT_FAILURE when the specified directory does not exist. And you got conditional processing symbols, so you could do like the below for this.

SET cd_backup=%cd%
(CD "%~1" && CD %cd_backup%) || GOTO Error

:Error
CD %cd_backup%
3

The NUL technique seems to only work on 8.3 compliant file names.

(In other words, `D:\Documents and Settings` is "bad" and `D:\DOCUME~1` is "good")


I think there is some difficulty using the "NUL" tecnique when there are SPACES in the directory name, such as "Documents and Settings."

I am using Windows XP service pack 2 and launching the cmd prompt from %SystemRoot%\system32\cmd.exe

Here are some examples of what DID NOT work and what DOES WORK for me:

(These are all demonstrations done "live" at an interactive prompt. I figure that you should get things to work there before trying to debug them in a script.)

This DID NOT work:

D:\Documents and Settings>if exist "D:\Documents and Settings\NUL" echo yes

This DID NOT work:

D:\Documents and Settings>if exist D:\Documents and Settings\NUL echo yes

This DOES work (for me):

D:\Documents and Settings>cd ..

D:\>REM get the short 8.3 name for the file

D:\>dir /x

Volume in drive D has no label. Volume Serial Number is 34BE-F9C9

Directory of D:\
09/25/2008 05:09 PM <DIR> 2008
09/25/2008 05:14 PM <DIR> 200809~1.25 2008.09.25
09/23/2008 03:44 PM <DIR> BOOST_~3 boost_repo_working_copy
09/02/2008 02:13 PM 486,128 CHROME~1.EXE ChromeSetup.exe
02/14/2008 12:32 PM <DIR> cygwin

[[Look right here !!!! ]]
09/25/2008 08:34 AM <DIR> DOCUME~1 Documents and Settings

09/11/2008 01:57 PM 0 EMPTY_~1.TXT empty_testcopy_file.txt
01/21/2008 06:58 PM <DIR> NATION~1 National Instruments Downloads
10/12/2007 11:25 AM <DIR> NVIDIA
05/13/2008 09:42 AM <DIR> Office10
09/19/2008 11:08 AM <DIR> PROGRA~1 Program Files
12/02/1999 02:54 PM 24,576 setx.exe
09/15/2008 11:19 AM <DIR> TEMP
02/14/2008 12:26 PM <DIR> tmp
01/21/2008 07:05 PM <DIR> VXIPNP
09/23/2008 12:15 PM <DIR> WINDOWS
02/21/2008 03:49 PM <DIR> wx28
02/29/2008 01:47 PM <DIR> WXWIDG~2 wxWidgets
3 File(s) 510,704 bytes
20 Dir(s) 238,250,901,504 bytes free

D:\>REM now use the \NUL test with the 8.3 name

D:\>if exist d:\docume~1\NUL echo yes

yes

This works, but it's sort of silly, because the dot already implies i am in a directory:

D:\Documents and Settings>if exist .\NUL echo yes

pestophagous
  • 4,069
  • 3
  • 33
  • 42
  • 1
    The problem appears to be not with long file names but directories with spaces in their names. Or rather, it's the quotes around the variable name that stop the NUL trick from working. I've added some code to my answer which converts file names to 8.3 names before testing. – David Webb Sep 29 '08 at 13:28
  • 2
    The NUL technique **DOES NOT WORK** with [Directory Symbolic Links (Softlinks) or Junctions](http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html): Files whose path contains a Directory Link are misrecognized as Directory. To reproduce, type: `cmd` [++](http://blogs.msdn.com/b/tims/archive/2006/11/02/windows-vista-secret-10-open-an-elevated-command-prompt-in-six-keystrokes.aspx) `mklink /d LinkDir .` `cd LinkDir` `if exist regedt32.exe\nul echo File erroneously detected as Directory` `rd .` – Aaron Thoma Jun 23 '12 at 19:45
3

This works and also handles paths with spaces in them:

dir "%DIR%" > NUL 2>&1

if not errorlevel 1 (
    echo Directory exists.
) else (
    echo Directory does not exist.
)

Probably not the most efficient but easier to read than the other solutions in my opinion.

Samuel
  • 8,063
  • 8
  • 45
  • 41
  • 1
    I liked your answer as the simplest. For some reason I don't understand it suddenly stopped working so I posted an answer [here](http://stackoverflow.com/questions/10071300/how-to-create-a-batch-file-which-work-for-both-program-files-and-program-filesx/31095955#31095955). – Chris Murphy Jun 28 '15 at 03:55
  • Alternative take: if you can `cd` into it... of course, remember your current dir before `set cwd=%cd%` to restore later... – Frank N Oct 25 '15 at 12:15
  • 2
    This verifies the path exists, but does not distinguish between a file or a folder. – dbenham Dec 25 '15 at 18:15
  • The suggestion does not work for me. To fix it, use `dir "%DIR%" /A:D > NUL 2>&1` to cause `dir` to exit with error code not equal to 0 for files. – Michael Podlejska Feb 11 '23 at 18:59
3

I use this:

if not [%1] == [] (
  pushd %~dpn1 2> nul
  if errorlevel == 1 pushd %~dp1
)
Kimae
  • 31
  • 1
2

A very simple way is to check if the child exists.

If a child does not have any child, the exist command will return false.

IF EXIST %1\. (
  echo %1 is a folder
) else (
  echo %1 is a file
)

You may have some false negative if you don't have sufficient access right (I have not tested it).

Eva Dias
  • 1,709
  • 9
  • 36
  • 67
Cedric
  • 29
  • 1
2

If you can cd into it, it's a directory:

set cwd=%cd%

cd /D "%1" 2> nul
@IF %errorlevel%==0 GOTO end

cd /D "%~dp1"
@echo This is a file.

@goto end2
:end
@echo This is a directory
:end2

@REM restore prior directory
@cd %cwd%
Frank N
  • 9,625
  • 4
  • 80
  • 110
1

Based on this article titled "How can a batch file test existence of a directory" it's "not entirely reliable".

BUT I just tested this:

@echo off
IF EXIST %1\NUL goto print
ECHO not dir
pause
exit
:print
ECHO It's a directory
pause

and it seems to work

Aaron Thoma
  • 3,820
  • 1
  • 37
  • 34
RomanM
  • 6,363
  • 9
  • 33
  • 41
  • 3
    Reading the article "unreliable" means that it failed on Pathworks, Novell, DR-DOS and OS/2 which I doubt will be a problem for most people. – David Webb Sep 26 '08 at 12:46
  • hence "not entirely reliable" – RomanM Sep 26 '08 at 12:54
  • 3
    **THIS DOES NOT WORK** with [Directory Symbolic Links (Softlinks) or Junctions](http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html): Files whose path contains a Directory Link are misrecognized as Directory. To reproduce, type: `cmd` [++](http://blogs.msdn.com/b/tims/archive/2006/11/02/windows-vista-secret-10-open-an-elevated-command-prompt-in-six-keystrokes.aspx) `mklink /d LinkDir .` `cd LinkDir` `if exist "regedt32.exe\NUL" echo File erroneously detected as Directory` `rd .` – Aaron Thoma Jun 24 '12 at 11:10
1

Here's my solution:

REM make sure ERRORLEVEL is 0
TYPE NUL

REM try to PUSHD into the path (store current dir and switch to another one)
PUSHD "insert path here..." >NUL 2>&1

REM if ERRORLEVEL is still 0, it's most definitely a directory
IF %ERRORLEVEL% EQU 0 command...

REM if needed/wanted, go back to previous directory
POPD
user966939
  • 692
  • 8
  • 27
1

I would like to post my own function script about this subject hope to be useful for someone one day.

@pushd %~dp1
@if not exist "%~nx1" (
        popd
        exit /b 0
) else (
        if exist "%~nx1\*" (
                popd
                exit /b 1
        ) else (
                popd
                exit /b 3
        )
)

This batch script checks if file/folder is exist and if it is a file or a folder.

Usage:

script.bat "PATH"

Exit code(s):

0: file/folder doesn't exist.

1: exists, and it is a folder.

3: exists, and it is a file.

M. Jamal
  • 11
  • 2
0

This is the code that I use in my BATCH files

```
@echo off
set param=%~1
set tempfile=__temp__.txt
dir /b/ad > %tempfile%
set isfolder=false
for /f "delims=" %%i in (temp.txt) do if /i  "%%i"=="%param%" set isfolder=true
del %tempfile%
echo %isfolder%
if %isfolder%==true echo %param% is a directory

```

gialloporpora
  • 199
  • 2
  • 11
0

Here is my solution after many tests with if exist, pushd, dir /AD, etc...

@echo off
cd /d C:\
for /f "delims=" %%I in ('dir /a /ogn /b') do (
    call :isdir "%%I"
    if errorlevel 1 (echo F: %%~fI) else echo D: %%~fI
)
cmd/k

:isdir
echo.%~a1 | findstr /b "d" >nul
exit /b %errorlevel%

:: Errorlevel
:: 0 = folder
:: 1 = file or item not found
  • It works with files that have no extension
  • It works with folders named folder.ext
  • It works with UNC path
  • It works with double-quoted full path or with just the dirname or filename only.
  • It works even if you don't have read permissions
  • It works with Directory Links (Junctions).
  • It works with files whose path contains a Directory Link.
Amr Ali
  • 3,020
  • 1
  • 16
  • 11
0

One issue with using %%~si\NUL method is that there is the chance that it guesses wrong. Its possible to have a filename shorten to the wrong file. I don't think %%~si resolves the 8.3 filename, but guesses it, but using string manipulation to shorten the filepath. I believe if you have similar file paths it may not work.

An alternative method:

dir /AD %F% 2>&1 | findstr /C:"Not Found">NUL:&&(goto IsFile)||(goto IsDir)

:IsFile
  echo %F% is a file
  goto done

:IsDir
  echo %F% is a directory
  goto done

:done

You can replace (goto IsFile)||(goto IsDir) with other batch commands:
(echo Is a File)||(echo is a Directory)

Kevin Fegan
  • 1,292
  • 1
  • 16
  • 29
TechGuy
  • 9
  • 1
  • 2
    No, of course `%~s1` doesn't "guess"/string-manipulate the short file name, it resolves it correctly. Like `dir /x` – Aaron Thoma Jun 24 '12 at 11:21
0

If your objective is to only process directories then this will be useful.

This is taken from the https://ss64.com/nt/for_d.html

Example... List every subfolder, below the folder C:\Work\ that has a name starting with "User":

CD \Work
FOR /D /r %%G in ("User*") DO Echo We found

FOR /D or FOR /D /R

@echo off
cd /d "C:\your directory here"
for /d /r %%A in ("*") do echo We found a folder: %%~nxA
pause

Remove /r to only go one folder deep. The /r switch is recursive and undocumented in the command below.

The for /d help taken from command for /?

FOR /D %variable IN (set) DO command [command-parameters]

If set contains wildcards, then specifies to match against directory names instead of file names.

Ste
  • 1,729
  • 1
  • 17
  • 27
  • 2
    This is an answer to another question. It doesn't fit to THIS question about detection if a given filename is a directory. – jeb Jan 24 '20 at 12:43
  • Seeing as the question has been answered to death. This just allows the user to process directories and skip the checking part. – Ste Jan 24 '20 at 13:32
0

Under Windows 7 and XP, I can't get it to tell files vs. dirs on mapped drives. The following script:

@echo off
if exist c:\temp\data.csv echo data.csv is a file
if exist c:\temp\data.csv\ echo data.csv is a directory
if exist c:\temp\data.csv\nul echo data.csv is a directory
if exist k:\temp\nonexistent.txt echo nonexistent.txt is a file
if exist k:\temp\something.txt echo something.txt is a file
if exist k:\temp\something.txt\ echo something.txt is a directory
if exist k:\temp\something.txt\nul echo something.txt is a directory

produces:

data.csv is a file
something.txt is a file
something.txt is a directory
something.txt is a directory

So beware if your script might be fed a mapped or UNC path. The pushd solution below seems to be the most foolproof.

user117529
  • 663
  • 8
  • 16
0

I was looking for this recently as well, and had stumbled upon a solution which has worked for me, but I do not know of any limitations it has (as I have yet to discover them). I believe this answer is similar in nature to TechGuy's answer above, but I want to add another level of viability. Either way, I have had great success expanding the argument into a full fledged file path, and I believe you have to use setlocal enableextensions for this to work properly.

Using below I can tell if a file is a directory, or opposite. A lot of this depends on what the user is actually needing. If you prefer to work with a construct searching for errorlevel vs && and || in your work you can of course do so. Sometimes an if construct for errorlevel can give you a little more flexibility since you do not have to use a GOTO command which can sometimes break your environment conditions.

@Echo Off
setlocal enableextensions

Dir /b /a:D "%~f1" && Echo Arg1 is a Folder || Echo Arg1 is NOT a Folder

Dir /b /a:-D "%~f1" && Echo Arg1 is a File || Echo Arg1 is NOT a File

pause

Using this you could simply drag and drop your file(s) onto the tool you are building to parse them out. Conversely, if you are using other means to comb your file structure and you already have the file and are not dragging/dropping them onto the batch file, you could implement this:

@Echo Off
setlocal enableextensions


Dir /b /s "C:\SomeFolderIAmCombing\*" >"%~dp0SomeFiletogoThroughlater.txt"

For /f "Usebackq Delims=" %%a in ("%~dp0SomeFiletogoThroughlater.txt") do (
  Call:DetectDir "%%a"
)

REM Do some stuff after parsing through Files/Directories if needed.  
REM GOTO:EOF below is used to skip all the subroutines below.

REM Using ' CALL:DetectDir "%%a" ' with the for loop keeps the for 
REM loop environment running in the background while still parsing the given file
REM in a clean environment where GOTO and other commmands do not need Variable Expansion.

GOTO:EOF

:DetectDir [File or Folder being checked]

REM Checks if Arg1 is a Directory.  If yes, go to Dir coding. If not, go to File coding.
Dir /b /a:D "%~f1" && Echo Arg1 is a Folder & GOTO:IsDir || Echo Arg1 is NOT a Folder & GOTO:IsFile

REM Checks if Arg1 is NOT a Directory.  If Yes, go to File coding.  If not, go to Dir coding
Dir /b /a:-D "%~f1" && Echo Arg1 is a File & GOTO:IsFile || Echo Arg1 is NOT a File & GOTO:IsDir

:IsDir
  REM Do your stuff to the Folder
GOTO:EOF

:IsFile
  REM do your stuff to the File
GOTO:EOF
k1dfr0std
  • 379
  • 1
  • 15
-3

Can't we just test with this :

IF [%~x1] == [] ECHO Directory

It seems to work for me.

Lucien Baron
  • 115
  • 6