Link to home
Start Free TrialLog in
Avatar of Boskop
Boskop

asked on

'IF EXIST' in a .bat script to test for an empty directory


I would like to test if an directory is empty, using a simple batch script.
I wrote the following line:


if not exist "%ProgramFiles%\Epos9300\nul" echo Path does not exist

My Problem is:
I want to run this batch file in Windows XP operating systems with different languages.
For example in the English windows version the system variable %ProgramFiles% includes a white space.  (...\Program Files\...)


Therefore I must put the whole path into double quotas.
But with double quotas the 'exist' command does not recognize an empty directory anymore.
ASKER CERTIFIED SOLUTION
Avatar of mkdonohue
mkdonohue

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Alternatively, use the valid shortname for %ProgramFiles% - e.g. C:\Progra~1\
Avatar of Boskop
Boskop

ASKER

mkdonohue, it's a good idea. Maybe there is one other suggestion to do it without changing the current path.

smilingpolitely, with your solution it is not sure that this is the real path name. Maybe it's C:\Progra~2\ or C:\Whewhe~1\ in another language like suaheli.