Windows 10

How to Check If a Path is File or Directory using Batch

In this tutorial, we are going to see how to check if a path is a file or directory using batch. Batch file contains a series of DOS (Disk Operating System) instructions. It allows triggering the execution of commands found in this file.
 

How to Check If a Path is File or Directory using Batch

The following example check if “C:\Users\StackHowTo\myFolders” exists and check if the path is a file or directory:

@echo off

if exist "C:\Users\StackHowTo\myFolders" (
  echo Is a folder
) else if exist "C:\Users\StackHowTo\myFolders" (
  echo Is a file
) else (
  echo Does not exist
)

Output:

Is a folder

4 thoughts on “How to Check If a Path is File or Directory using Batch

  • Uh, you’re only checking if the path exists……….

    Reply
    • Why Email

      I thought I was crazy… and isn’t it checking the same existence twice?

      Reply
  • Thanks, wasted 2 minutes of my time trying to find any difference between two if’s.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *