Hallo zusammen,ich habe das jetzt nochmal unter 2016.2.1 getestet. Dabei existiert "C:\Temp", während "C:\Temp2" nicht vorhanden ist.If Exist('%SystemDrive%\Temp')
MsgBox
%SystemDrive%\Temp existiert.
EndProc
If not Exist('%SystemDrive%\Temp')
MsgBox
%SystemDrive%\Temp existiert nicht.
EndProc
!
If Exist('%SystemDrive%\Temp2')
MsgBox
%SystemDrive%\Temp2 existiert.
EndProc
If not Exist('%SystemDrive%\Temp2')
MsgBox
%SystemDrive%\Temp2 existiert nicht.
EndProc
Und alle vier Abfragen arbeiten richtig.09:23:32.547 1 Evaluating condition "Exist('_SystemDrive_\Temp')"
09:23:32.547 2 Condition TRUE -> entering IF part
09:23:32.548 2 -> MsgBox C:\Temp existiert.
09:23:35.620 1 Evaluating condition "not Exist('_SystemDrive_\Temp')"
09:23:35.621 2 Condition FALSE -> skipping IF part
09:23:35.622 2 Skipping command : MsgBox
09:23:35.623 1 Evaluating condition "Exist('_SystemDrive_\Temp2')"
09:23:35.624 2 Condition FALSE -> skipping IF part
09:23:35.625 2 Skipping command : MsgBox
09:23:35.626 1 Evaluating condition "not Exist('_SystemDrive_\Temp2')"
09:23:35.627 2 Condition TRUE -> entering IF part
09:23:35.628 2 -> MsgBox C:\Temp2 existiert nicht.
Allerdings wird hier nicht unterschieden, ob es sich um ein Verzeichnis oder eine Datei handelt. Wenn es eine Datei "C:\Temp2" gibt (ohne Dateiendung, ist ja durchaus möglich), dann liefert die If-Abfrage ebenfalls "true" - dummerweise hilft unter Windows auch die AbfrageIf Exist('%SystemDrive%\Temp2\.')
MsgBox
%SystemDrive%\Temp2 existiert.
EndProc
If not Exist('%SystemDrive%\Temp2\.')
MsgBox
%SystemDrive%\Temp2 existiert nicht.
EndProc
nicht weiter, auch diese liefert True, egal, ob Temp2 eine Datei oder ein Verzeichnis ist.Was man noch prüfen kann (über WMI waren meine Versuche nicht wirklich erfolgreich, da die Klasse Win32_Directory zu viele Instanzen besitzt), ist bei Existenz noch mit der cmd.exe abzufragen, ob das Objekt ein Verzeichnis ist:Set('DirPath','%SystemDrive%\Temp')
If Exist('%DirPath%')
MsgBox
%DirPath% existiert.
EndProc
Set('returncode','0')
RunAsEx('%WINSYSDIR%\cmd.exe','/c dir /ad "%DirPath%"','','','2','returncode',raUseSisAccount+WaitForExecution+raHideWindow+UndoneContinueParentScript)/TW
If %returncode%='0'
MsgBox
%DirPath% ist ein Verzeichnis
EndProc
Else
MsgBox
%DirPath% ist eine Datei
EndProc
If not Exist('%DirPath%')
MsgBox
%DirPath% existiert nicht.
EndProc
!
Set('DirPath','%SystemDrive%\Temp2')
If Exist('%DirPath%')
MsgBox
%DirPath% existiert.
EndProc
Set('returncode','0')
RunAsEx('%WINSYSDIR%\cmd.exe','/c dir /ad "%DirPath%"','','','2','returncode',raUseSisAccount+WaitForExecution+raHideWindow+UndoneContinueParentScript)/TW
If %returncode%='0'
MsgBox
%DirPath% ist ein Verzeichnis
EndProc
Else
MsgBox
%DirPath% ist eine Datei
EndProc
If not Exist('%DirPath%')
MsgBox
%DirPath% existiert nicht.
EndProc
GrußNils