ich habe nach der Möglichkeit gesucht, einen Ordner mit Progressbar zu kopieren. Habe hier im Forum viele Postings diesbezüglich gelesen und die Codes ausprobiert. Aber ich habe keinen gefunden der wirklich funktionierte. Also hab ich mir selbst was gebastelt.
Vielleicht kanns ja noch jemand gebrauchen....
Für diesen Code wird die PureFile Libary von Philippe 'gnozal' Guntz benötigt.
Diese findet Ihr hier:
http://people.freenet.de/gnozal/PureFILE_.zip
Code: Alles auswählen
;Window
Enumeration
#Window_CopyProgress
EndEnumeration
;Gadgets
Enumeration
#ProgressBar_0
#TG_headline
#TG_von
#TG_vonV
#TG_nach
#TG_nachV
#TG_progressV
EndEnumeration
Global fil.l ;hochzählen Progressstatus
Global src.s = "g:\purebasic_libs\" ;PFAD ANPASSEN
Global dst.s = "d:\test\" ;PFAD ANPASSEN
Global fAnz.l ;max. Wert der Progressbar
;#####################################
;Diese Prozedur ist 1:1 aus dem CodeArchiv übernommen.
;Sie dient zum ermitteln des Max. Wertes der Progressbar
;Danke an benny (Author) und HeXOR fürs Update auf 4.0
;#####################################
Procedure.l CountFiles(Dir.s)
Protected ID.l, files.l
If Right(Dir, 1) <> "\"
Dir + "\"
EndIf
ID = ExamineDirectory(#PB_Any, Dir, "")
If ID
While NextDirectoryEntry(ID)
Select DirectoryEntryType(ID)
Case 0
Break
Case #PB_DirectoryEntry_File
files + 1
Case #PB_DirectoryEntry_Directory
If DirectoryEntryName(ID) <> "." And DirectoryEntryName(ID) <> ".."
files + CountFiles(Dir + DirectoryEntryName(ID))
EndIf
EndSelect
Wend
EndIf
ProcedureReturn files
EndProcedure
;#######################################
;Diese Prozedur habe ich hier aus dem Forum
;http://www.purebasic.fr/german/viewtopic.php?t=11150&start=0&postdays=0&postorder=asc&highlight=pbescanpath
;Danke an Didelphodon (Author) und AND51 fürs optimieren
;#######################################
Procedure PBE_ScanPath(Path.s, *callbackProc) ; Scan the given path recursively and call callback (format dirId.l, path.s) (optimized by AND51)
Protected dir.l, name.s, files.l;, fil.l
If *callbackProc = 0 : ProcedureReturn #False : EndIf
If Right(Path, 1) <> "\" : Path + "\" : EndIf
dir = ExamineDirectory(#PB_Any, Path, "")
If dir
While NextDirectoryEntry(dir)
name = DirectoryEntryName(dir)
If name <> "." And name <> ".."
If DirectoryEntryType(dir) = #PB_DirectoryEntry_Directory
files + PBE_ScanPath(Path + name + "\", *callbackProc)
Else
files + 1
CallFunctionFast(*callbackProc, Path + name)
EndIf
EndIf
Wend
FinishDirectory(dir)
ProcedureReturn files
EndIf
ProcedureReturn #False
EndProcedure
Procedure FileCallback(File.s)
fPath.s = GetPathPart(File) ;Pfad der Datei ermitteln
fLen.l = Len(File) ;länge des Dateipfades ermitteln
sLen.l = Len(src) ;länge des Quellpfades ermitteln
pLen.l = fLen - sLen ;länge des Quellpfades von der länge des Dateipfades abziehen
sub.s = Right(File, pLen) ;Pfad ohne Quellpfad und Dateinmae ermitteln
If FileSize(File) = -2
PureFILE_CreateDirectory(dst + sub)
Else
If FileSize(dst + sub) = -2
CopyFile(File, dst + sub)
SetGadgetText(#TG_vonV, File)
SetGadgetText(#TG_nachV, dst + sub)
Else
PureFILE_CreateDirectory(dst + sub)
CopyFile(File, dst + sub)
SetGadgetText(#TG_vonV, File)
SetGadgetText(#TG_nachV, dst + sub)
EndIf
EndIf
fil = fil + 1 ;Progressstatus um 1 erhöhen
SetGadgetState(#ProgressBar_0, fil)
SetGadgetText(#TG_progressV, Str(fil) + " von " + Str(fAnz) + " Dateien kopiert")
EndProcedure
fAnz.l = CountFiles(src) ;anzahl der Dateien im Quellverzeichnis ermitteln
If OpenWindow(#Window_CopyProgress, 475, 369, 482, 132, "Kopiervorgang...", #PB_Window_SizeGadget|#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(#Window_CopyProgress))
ProgressBarGadget(#ProgressBar_0, 5, 85, 475, 20, 0, fAnz, #PB_ProgressBar_Smooth)
TextGadget(#TG_von, 5, 5, 45, 15, "Quelle:")
TextGadget(#TG_vonV, 5, 20, 475, 15, "")
TextGadget(#TG_nach, 5, 45, 45, 15, "Ziel:")
TextGadget(#TG_nachV, 5, 60, 475, 15, "")
TextGadget(#TG_progressV, 5, 110, 475, 15, "", #PB_Text_Center)
EndIf
EndIf
Debug PBE_ScanPath(src, @FileCallback())
getestet unter: WinXP Pro SP2
überprüft mit: DirComp v2.6 http://www.lab1.de/Central/Software/Dat ... s/Dircomp/
Gruss
Marco