Skip to content

Instantly share code, notes, and snippets.

@phx
Created August 14, 2013 06:06
Show Gist options
  • Select an option

  • Save phx/6228418 to your computer and use it in GitHub Desktop.

Select an option

Save phx/6228418 to your computer and use it in GitHub Desktop.
check to see whether a file exists in cmd.exe
if exist {insert file name here} (
rem file exists
) else (
rem file doesn't exist
)
# or on a single line (if only a single action needs to occur):
if exist {insert file name here} {action}
# a quick little example testing for both files and/or directories:
md foo
echo.>bar
for %I in (foo bar xyz) do @(
if exist %I (
if exist %I\nul (
echo -- %I is a directory
) else (
echo -- %I is a file
)
) else (
echo -- %I does not exist
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment