Gibt es eine einfache Möglichkeit zu prüfen ob eine Datei gerade in Benutzung ist und deswegen nicht verschoben werden kann?
FileGetAttrib liefert leider nichts brauchbares. Die Datei verschieben und den Rückgabewert prüfen ist auch keine Lösung für mich da mehrere Dateien aus unterschiedlichen Ordnern verschoben werden müssen und die Regel gilt, entweder alle verschieben oder gar keine.
Prüfen ob eine Datei in Benutzung ist
-
- [ gelöst ]
-
Bitboy -
23. Juni 2009 um 10:15 -
Geschlossen -
Erledigt
-
-
Ich hätte das jetzt so gemacht:
Spoiler anzeigen
[autoit]MsgBox(0, "", _IsOpen("C:\Programme\BKSoft\Desktop Radio©\Desktop Radio.exe"))
[/autoit] [autoit][/autoit] [autoit]Func _IsOpen($PathToFile)
[/autoit] [autoit][/autoit] [autoit]
Local $Path
Local $OldNameSplit = StringSplit($PathToFile, "\")
$OldName = $OldNameSplit[$OldNameSplit[0]]For $NextLoop = 1 To $OldNameSplit[0] - 1
[/autoit] [autoit][/autoit] [autoit]
$Path &= $OldNameSplit[$NextLoop] & "\"
Next$Path = StringTrimRight($Path, 1)
[/autoit] [autoit][/autoit] [autoit]If FileMove($PathToFile, $Path & "\SDF5SF4DS5F5D.dat") = @error Then
[/autoit] [autoit][/autoit] [autoit]
Return False
Else
FileMove($Path & "\SDF5SF4DS5F5D.dat", $Path & "\" & $OldName)
Return True
EndIfEndFunc ;==>_IsOpen
[/autoit] -
Hab grade im Englischen Forum folgende Funktion gefunden:
Spoiler anzeigen
[autoit];from this post:
[/autoit]
;Need help with copy verification
;http://www.autoitscript.com/forum/index.php?showtopic=53994
;===============================================================================
;
; Function Name: _FileInUse()
; Description: Checks if file is in use
; Syntax.........: _FileInUse($sFilename, $iAccess = 1)
; Parameter(s): $sFilename = File name
; Parameter(s): $iAccess = 0 = GENERIC_READ - other apps can have file open in readonly mode
; $iAccess = 1 = GENERIC_READ|GENERIC_WRITE - exclusive access to file,
; fails if file open in readonly mode by app
; Return Value(s): 1 - file in use (@error contains system error code)
; 0 - file not in use
; -1 dllcall error (@error contains dllcall error code)
; Author: Siao
; Modified rover - added some additional error handling, access mode
; Remarks _WinAPI_CreateFile() WinAPI.au3
;===============================================================================
Func _FileInUse($sFilename, $iAccess = 0)
Local $aRet, $hFile, $iError, $iDA
Local Const $GENERIC_WRITE = 0x40000000
Local Const $GENERIC_READ = 0x80000000
Local Const $FILE_ATTRIBUTE_NORMAL = 0x80
Local Const $OPEN_EXISTING = 3
$iDA = $GENERIC_READ
If BitAND($iAccess, 1) <> 0 Then $iDA = BitOR($GENERIC_READ, $GENERIC_WRITE)
$aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _
"str", $sFilename, _ ;lpFileName
"dword", $iDA, _ ;dwDesiredAccess
"dword", 0x00000000, _ ;dwShareMode = DO NOT SHARE
"dword", 0x00000000, _ ;lpSecurityAttributes = NULL
"dword", $OPEN_EXISTING, _ ;dwCreationDisposition = OPEN_EXISTING
"dword", $FILE_ATTRIBUTE_NORMAL, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL
"hwnd", 0) ;hTemplateFile = NULL
$iError = @error
If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, -1)
$hFile = $aRet[0]
If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1
$aRet = DllCall("Kernel32.dll", "int", "GetLastError")
;ERROR_SHARING_VIOLATION = 32 0x20
;The process cannot access the file because it is being used by another process.
If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, 1)
Return SetError($aRet[0], 0, 1)
Else
;close file handle
DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile)
Return SetError(@error, 0, 0)
EndIf
EndFuncWerde deine Funktion auch noch ausprobieren.
-
hi...
wäre das nicht einfacher mit fileopen ( im schreibmodus ) gegangen und wenn error kommt ist es in benutzung ....
MFG chris
-
Mist. funktioniert leider nur mit MS Office Dokumenten. Bei anderen Dateien die mit Notepad oder so erstellt worden sind funktioniert es nicht mehr