Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5870
  • Last Modified:

'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.
0
Boskop
Asked:
Boskop
1 Solution
 
mkdonohueCommented:
Why not just CD to the %ProgramFiles% directory in your scrip and then check for the existance of Epos9300\nul?
0
 
smilingpolitelyCommented:
Alternatively, use the valid shortname for %ProgramFiles% - e.g. C:\Progra~1\
0
 
BoskopAuthor Commented:
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.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now