Created
August 14, 2013 06:06
-
-
Save phx/6228418 to your computer and use it in GitHub Desktop.
check to see whether a file exists in cmd.exe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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