Friday, January 30, 2009

IF EXIST for directories

Sometimes you simply need to use batch files, although they are something from the past. In a current project, a custom made service wanted to copy a given file using a batch file. This didn't worked on all machines, because the customer has started to roll out MUI installations where the userprofile folder differs:

Default Windows XP (German) profile folder: C:\Dokumente und Einstellungen\
Default Windows XP (MUI) profile folder: C:\Document and Settings\

The solution (seems) rather simple:

IF EXIST "%SYSTEMDRIVE%\Dokumente und Einstellungen" GOTO DEUTSCH

Well, this doesn't work because IF EXIST can only check for files, but not for folders. The trick is to append "\." at the end because every folder contains this "virtual file". Therefore, the batch would look like this:

IF EXIST "%SYSTEMDRIVE%\Dokumente und Einstellungen\." GOTO DEUTSCH

GOTO ENGLISH





:DEUTSCH

echo German XP

goto ende



:ENGLISH

echo English or MUI XP

goto ende



:ende

pause

No comments:

Post a Comment