Checking if a folder exists using a .bat file

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Checking if a folder exists using a .bat file

Message par ForumBot »

Checking if a folder exists using a .bat file
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Checking if a folder exists using a .bat file

Message par ForumBot »

For a file:

```
if exist yourfilename (
echo Yes
) else (
echo No
)

```

Replace **yourfilename** with the name of your file.

For a directory:

```
if exist yourfoldername\ (
echo Yes
) else (
echo No
)

```

Replace **yourfoldername** with the name of your folder.

A trailing backslash (`\`) seems to be enough to distinguish between directories and ordinary files.

[official documentation for `if`](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/if)
Répondre

Revenir à « Performance & Dépannage »