| FrontBack |
| | Eccomi qua, a fare una nuova UDF che copia e sposta file (senza barra di progresso, l'ho fatta apposta per eliminarla). Il log degli errori è esaustivo: Se qualcosa non va, @error = 0 e @extended = ... _FileCopy- 0x000 = File di partenza inesistente - 0x001 = Impossibile aprire il file di partenza - 0x002 = (solo con Overwrite = True) Impossibile cancellare il file di destinazione esistente - 0x003 = Impossibile scrivere il nuovo file _FileMove- 0x000 = File di partenza inesistente - 0x001 = Impossibile aprire il file di partenza - 0x002 = (solo con Overwrite = True) Impossibile cancellare il file di destinazione esistente - 0x003 = Impossibile scrivere il nuovo file - 0x004 = Impossibile cancellare il file di origine In entrambi i casi se l'operazione riesce le funzioni ritorneranno 1. ParametriCODICE _FileCopy(<Percorso del file di origine>, <Percorso del file di destinazione (se inesistente verrà creato)>, <(opzionale) Sovrascrivi, se falso al nome del nuovo file sarà aggiunto un numero progressivo>) CODICE _FileMove(<Percorso del file di origine>, <Percorso del file di destinazione (se inesistente verrà creato)>, <(opzionale) Sovrascrivi, se falso al nome del nuovo file sarà aggiunto un numero progressivo>) CodiceEccovi il codice: CODICE #include <File.au3>
Func _FileCopy($fStartPath, $fEndPath, $bOverwrite = False) Dim $szDrive, $szDir, $szFName, $szExt If Not FileExists($fStartPath) Then SetError(0, 0x000) $open = FileOpen($fStartPath, 16) If @error Then SetError(0, 0x001) $read = FileRead($open, FileGetSize($fStartPath)) If $bOverwrite = True And FileExists($fEndPath) Then FileDelete($fEndPath) If @error Then SetError(0, 0x002) $open = FileOpen($fEndPath, 16+8+2) FileWrite($open, $read) If @error Then SetError(0, 0x003) FileClose($open) Return 1 ElseIf $bOverwrite = True And Not FileExists($fEndPath) Then $split = _PathSplit($fEndPath, $szDrive, $szDir, $szFName, $szExt) Local $count = 2 Do If FileExists($split[1]&$split[2]&$split[3]&" ("&$count&")"&$split[4]) Then $count += 1 FileWrite($split[1]&$split[2]&$split[3]&" ("&$count&")"&$split[4], $read) If @error Then SetError(0, 0x003) $count += 1 Until Not FileExists($split[1]&$split[2]&$split[3]&" ("&$count&")"&$split[4]) FileClose($open) Return 1 ElseIf $bOverwrite = False And FileExists($fEndPath) Then $split = _PathSplit($fEndPath, $szDrive, $szDir, $szFName, $szExt) Local $count = 2 Do If FileExists($split[1]&$split[2]&$split[3]&" ("&$count&")"&$split[4]) Then $count += 1 FileWrite($split[1]&$split[2]&$split[3]&" ("&$count&")"&$split[4], $read) If @error Then SetError(0, 0x003) $count += 1 Until Not FileExists($split[1]&$split[2]&$split[3]&" ("&$count&")"&$split[4]) FileClose($open) Return 1 Else FileWrite($fEndPath, $read) If @error Then SetError(0, 0x003) FileClose($open) Return 1 EndIf EndFunc
Func _FileMove($fStartPath, $fEndPath, $bOverwrite = False) Dim $szDrive, $szDir, $szFName, $szExt If Not FileExists($fStartPath) Then SetError(0, 0x000) $open = FileOpen($fStartPath, 16) If @error Then SetError(0, 0x001) $read = FileRead($open, FileGetSize($fStartPath)) If $bOverwrite = True And FileExists($fEndPath) Then FileDelete($fEndPath) If @error Then SetError(0, 0x002) $open = FileOpen($fEndPath, 16+8+2) FileWrite($open, $read) If @error Then SetError(0, 0x003) FileClose($open) FileDelete($fStartPath) If @error Then SetError(0, 0x004) Return 1 ElseIf $bOverwrite = True And Not FileExists($fEndPath) Then $split = _PathSplit($fEndPath, $szDrive, $szDir, $szFName, $szExt) Local $count = 2 Do If FileExists($split[1]&$split[2]&$split[3]&" ("&$count&")"&$split[4]) Then $count += 1 FileWrite($split[1]&$split[2]&$split[3]&" ("&$count&")"&$split[4], $read) If @error Then SetError(0, 0x003) $count += 1 Until Not FileExists($split[1]&$split[2]&$split[3]&" ("&$count&")"&$split[4]) FileClose($open) FileDelete($fStartPath) If @error Then SetError(0, 0x004) Return 1 ElseIf $bOverwrite = False And FileExists($fEndPath) Then $split = _PathSplit($fEndPath, $szDrive, $szDir, $szFName, $szExt) Local $count = 2 Do If FileExists($split[1]&$split[2]&$split[3]&" ("&$count&")"&$split[4]) Then $count += 1 FileWrite($split[1]&$split[2]&$split[3]&" ("&$count&")"&$split[4], $read) If @error Then SetError(0, 0x003) $count += 1 Until Not FileExists($split[1]&$split[2]&$split[3]&" ("&$count&")"&$split[4]) FileClose($open) FileDelete($fStartPath) If @error Then SetError(0, 0x004) Return 1 Else FileWrite($fEndPath, $read) If @error Then SetError(0, 0x003) FileClose($open) FileDelete($fStartPath) If @error Then SetError(0, 0x004) Return 1 EndIf EndFunc
| | |
| |
|