UDX Posted June 7, 2009 Share Posted June 7, 2009 (edited) Hello. Unfortunately I am not a developer but I have been trying to learn some of it for years and still can't understand it for some reason so I wanted to ask for some help if possible. There is a program that I found while searching on forum that I want to use for copy/paste folder purposes which would actually be a backup solution for me. The original code copies predefined folder set to a different location and I wanted just refine it a bit more; What I was thinking of doing is adding a "destination folder made up of system date" (as a first step) 1. Capture the system date -> and convert that to a string 2. Reverse that string so it gets a format of (YYYY\MM\DD) 3. Strip away "\" from that string 4. Create a folder with that string on "destination" drive or folder as the "main folder" used 5. Execute copy / paste operation into that "main folder" Here's the code that I have been trying to work with (I have commented out the string part that I think it's very messy due to lack of my knowledge); So my question is what should I do to make this work? expandcollapse popup#cs ;~ This script is demonstrate copy process with custom designed progress displayed, the progress display details about the copy process. ;~ ;~ Syntax: _CopyWithProgress("C:\Source", "C:\Dest", 1) ;~ First parm is the source dir that files will be copied from. ;~ Second param is the destination path that files will be copied to. ;~ If the last parameter set as 1, then all existing files will be replaced with copied ones. ;~ ;~ Author: G.Sandler a.k.a CreatoR ;~ Functions _DirListToArray() and _FileListToArrayEx() is originaly writen by amel27. ;~ Further modded by damian666 #CE #include <AVIConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <GuiConstantsEx.au3> #include <Date.au3> #include <WindowsConstants.au3> #include <string.au3> #cs string $tDate; $tDate = _Date_Time_SystemTimeToDateTimeStr ($tDate) _StringReverse ($tDate); #ce _CopyWithProgress("C:\Source Folder", "C:\($tDate)", 1) Func _CopyWithProgress($SourcePath, $DestPath, $Replace=1) If Not FileExists($SourcePath) Then Return SetError(1, 0, -1) If Not StringInStr(FileGetAttrib($DestPath), "D") And Not DirCreate($DestPath) Then Return SetError(2, 0, "") If $Replace <> 0 And $Replace <> 1 Then SetError(3, 0, "") Local $PathName = StringRegExpReplace($SourcePath, "^.*\\", "") Local $Progress=0, $Counter, $ReadySize, $MidlePath, $Ready, $TimeRemained Local $CurrentFilePath, $CurrentFileName, $CurrentFilePathName, $CurrentParentDirName ;ProgressOn("Copy Files...", "Copy: " & $PathName, "Getting dir structure" & @LF & "Please wait...", -1, -1, 2 + 16) Local $TotalDirSize = DirGetSize($SourcePath) Local $FilesArr = _FileListToArrayEx($SourcePath) Local $FilesCount = UBound($FilesArr)-1 Local $ProgressStep = 100 / $FilesCount ;testdialog Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\Bureaublad\Form1.kxf $Form1 = GUICreate("Copying...", 401, 238, 193, 125, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS)) $Avi1 = GUICtrlCreateAvi(@ScriptDir & "\160.avi", -1, 0, 0, 400, 56, BitOR($ACS_TRANSPARENT,$ACS_AUTOPLAY)) $Progress1 = GUICtrlCreateProgress(8, 64, 385, 17) $Label1 = GUICtrlCreateLabel("From:", 8, 112, 36, 17) $Label2 = GUICtrlCreateLabel("", 56, 112, 338, 25) $Label3 = GUICtrlCreateLabel("Filecopy in progress...", 8, 88, 385, 17) $Label4 = GUICtrlCreateLabel("To:", 8, 152, 36, 17) $Label5 = GUICtrlCreateLabel("", 56, 151, 338, 25) $Button1 = GUICtrlCreateButton("Cancel", 337, 216, 59, 17, 0) GUICtrlSetOnEvent(-1, "Button1Click") $Label6 = GUICtrlCreateLabel("Approximately Remained Time:", 8, 184, 156, 17) $Label7 = GUICtrlCreateLabel("", 176, 184, 217, 17) $Label8 = GUICtrlCreateLabel("Already done:", 8, 208, 69, 17) $Label9 = GUICtrlCreateLabel("", 88, 208, 243, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ;end testdialog If IsArray($FilesArr) Then For $i = 1 To UBound($FilesArr)-1 $CurrentFilePath = $FilesArr[$i] $CurrentFileName = StringRegExpReplace($CurrentFilePath, "^.*\\", "") $CurrentFilePathName = StringReplace($CurrentFilePath, $SourcePath & "\", "") $CurrentParentDirName = _GetParentDirName($CurrentFilePath) $Progress += $ProgressStep $Counter += 1 $ReadySize = FileGetSize($CurrentFilePath) $MidlePath = _GetMidlePath($CurrentFilePath) $Ready = $Counter & "/" & $FilesCount $TimeRemained = _GetTimeRemained($TotalDirSize, $ReadySize, $FilesCount, $Counter) GUICtrlSetData($Label2, $CurrentFilePath) GUICtrlSetData($Label5, $DestPath & "\" & $CurrentFilePathName) GUICtrlSetData($Progress1, $Progress) GUICtrlSetData($Label7, $TimeRemained) GUICtrlSetData($Label9, $Ready) ;ProgressSet($Progress, "Copy... from " & $CurrentParentDirName & " to " & $CurrentParentDirName & @LF & _ ;$MidlePath & @LF & "Approximately Remained Time: " & $TimeRemained, "Ready: " & $Ready) FileCopy($CurrentFilePath, $DestPath & "\" & $CurrentFilePathName, 8+$Replace) Next EndIf ;ProgressOff() EndFunc Func _FileListToArrayEx($sPath, $sMask='*') Local $i, $j, $blist, $rlist[1]=[0], $dlist = _DirListToArray($sPath) _ArrayAdd ($dlist, $sPath) For $i=1 To $dlist [0] +1 $blist = _FileListToArray ($dlist [$i], $sMask, 1) If Not @error Then For $j=1 To $blist [0] _ArrayAdd ($rlist, $dlist[$i] & "\" & $blist [$j]) Next EndIf Next $rlist [0] = UBound ($rlist) - 1 Return $rlist EndFunc Func _DirListToArray($sPath) Local $rlist[2]=[1, $sPath], $blist, $alist=_FileListToArray ($sPath, '*', 2) If IsArray ($alist) Then For $i=1 To $alist [0] _ArrayAdd ($rlist, $sPath & "\" & $alist [$i]) $blist = _DirListToArray ($sPath & "\" & $alist [$i]) If $blist[0]>0 Then For $j=1 To $blist [0] _ArrayAdd ($rlist, $blist [$j]) Next EndIf Next EndIf $rlist[0] = UBound($rlist) - 1 Return $rlist EndFunc Func _GetMidlePath($sPath) If StringLen($sPath) <= 50 Then Return $sPath Local $StartPath = StringLeft($sPath, 25) Local $EndPath = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -2)-1) Return $StartPath & "..." & $EndPath EndFunc Func _GetParentDirName($FullName) Local $LastSlashPos = StringInStr($FullName, "\", 0, -1) Local $SecondLastSlashPos = StringInStr($FullName, "\", 0, -2) Return StringMid($FullName, $SecondLastSlashPos+1, $LastSlashPos-$SecondLastSlashPos-1) EndFunc Func _GetTimeRemained($TotalSize, $CurrentSize, $FilesCount, $CurrentFilesCount) Local $NumLevl = 0.5 If $TotalSize <= $CurrentSize Then Return _SecsToTime(0) Switch $FilesCount - $CurrentFilesCount Case 0 To 100 $NumLevl = 0.1 Case 100 To 1000 $NumLevl = 0.5 Case 1000 to 2000 $NumLevl = 1 Case Else $NumLevl = 2 EndSwitch $Secs = ($TotalSize * $NumLevl) / (3600 * $CurrentFilesCount) - ($CurrentSize * $NumLevl) / (3600 * $CurrentFilesCount) Return _SecsToTime($Secs) EndFunc Func _SecsToTime($iTicks, $Delim=":") If Number($iTicks) >= 0 Then $iHours = Int($iTicks / 3600) $iTicks = Mod($iTicks, 3600) $iMins = Int($iTicks / 60) $iSecs = Round(Mod($iTicks, 60)) If StringLen($iHours) = 1 Then $iHours = "0" & $iHours If StringLen($iMins) = 1 Then $iMins = "0" & $iMins If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs Return $iHours & $Delim & $iMins & $Delim & $iSecs EndIf Return SetError(1, 0, 0) EndFunc Func Button1Click() Exit EndFunc Edited June 7, 2009 by UDX Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now