1.

Solve : Check if a folder exist...?

Answer»

Hi there I've spent the last hours trying to move some files...
The COPY part is easy enough, but i can't find a command to check if a folder exist..

Please help me out

Bjerrumif exist foldername\ commands
Change commands to what you want it to do if the folder does exist.You don't need the trailing slash, and if the folder name has spaces, enclose it in quotes

if exist "test folder" echo OK

that does work- and all this time I've been doing "if exist \nul "Ty so much ... I'll try that tomorrow

night night Quote from: BC_Programmer on May 20, 2008, 02:36:48 PM

that does work- and all this time I've been doing "if exist <foldername>\nul <command>"

Checking for \nul is a venerable way of checking if a folder or drive exists. NUL always exists on a local MS-DOS FAT drive; therefore, if C:\ exists, then C:\NUL exists, and if C:\WIN exists, C:\WIN\NUL exists.

However it does not work in EVERY situation, and therefore is regarded as obsolete, and is not needed in NTFS.

The following table shows when IF EXIST returns NUL:


With 32-Bit File
No 32-Bit With 32-Bit Access and NetWare

Drive Type File Access File Access 3.x connectivity

Local FAT correctly always never
Windows for Workgroups FAT correctly always never
Microsoft LAN MANAGER HPFS never always never
Windows NT FAT/NTFS never always never
NetWare correctly never never


It's just a habit from my old batch programming days with DOS 3.21 since I don't really use batch anymore I don't have a bunch of batch files in my C:\BELFRY directory peppered with TESTS for the NUL file. Back when I first started I used If exist dir\*.*, which worked if there were any files. But without files it didn't work.

MS-DOS is phat. I was taught this way to check for a folder.
Code: [Select]if exist folder\. command

Every folder has a . directory, even if empty, so this test works in all versions. Quote from: llmeyer1000 on May 23, 2008, 08:38:06 PM
I was taught this way to check for a folder.
Code: [Select]if exist folder\. command

Every folder has a . directory, even if empty, so this test works in all versions.

we have a winner!


Discussion

No Comment Found