Sign in to follow this  
Followers 0
skippynz

need a fresh set of eyes

6 posts in this topic

#1 ·  Posted (edited)

i have this code below which does or should do the following

* list folders in a directory to an array

* if folder exists copy the folder contents to the users profile or system dir

but it seems to only copy over one folder (its not the first or last folder) so i have no idea whats going on

arrggghhh iif only i could see the error of my ways

$Folders = _FileListToArray(@ScriptDir & "\" & @UserName & "\","*",2)
    if not @error Then
        For $x = 1 To $Folders[0]
            $Folders2 = $Folders[$x]
            sleep(500)
            msgbox(0,"test",$Folders2)
            sleep(500)
            if $Folders2 == "My Documents" Then
                GUICtrlSetData ( $text, 'Restoring the "My Documents" folder ' )
                sleep(500)
                _rundos( 'xcopy.exe "' & @ScriptDir & '\' & @UserName & '\My Documents\*.*" "' & @MyDocumentsDir & '\*.*" /e /f /g /h /y /z > "My Documents_Restore.log"')
                sleep(500)
                _RunDOS('dir /s "' & @MyDocumentsDir & '" > "' & @ScriptDir & '\size.txt"')
                sleep(500)
                _FileReadToArray("size.txt", $size)
                sleep(500)
                $x = $size[0] - 2
                sleep(500)
                $size1 = StringStripWS($size[$x],3)
                sleep(500)
                FileWriteLine($backup_file, "--- My Documents --- <br>")
                sleep(500)
                FileWriteLine($backup_file, $size1 & ' <br>')
                sleep(500)
                FileWriteLine($backup_file, '<br>')
            EndIf
            sleep(500)
            if $Folders2 == "Desktop" Then
                GUICtrlSetData ( $text, 'Restoring the "Desktop" folder ' )
                sleep(500)
                _rundos( 'xcopy.exe "' & @ScriptDir & '\' & @UserName & '\Desktop\*.*" "' & @DesktopDir & '\*.*" /e /f /g /h /y /z > "Desktop_Restore.log"')
                sleep(500)
                _RunDOS('dir /s "' & @DesktopDir & '" > "' & @ScriptDir & '\size.txt"')
                sleep(500)
                _FileReadToArray("size.txt", $size)
                sleep(500)
                $x = $size[0] - 2
                sleep(500)
                $size1 = StringStripWS($size[$x],3)
                sleep(500)
                FileWriteLine($backup_file, "--- Desktop --- <br>")
                sleep(500)
                FileWriteLine($backup_file, $size1 & ' <br>')
                sleep(500)
                FileWriteLine($backup_file, '<br>')
            EndIf
            sleep(500)
            if $Folders2 == "Favorites" Then
                GUICtrlSetData ( $text, 'Restoring the "Favorites" folder ' )
                sleep(500)
                _rundos( 'xcopy.exe "' & @ScriptDir & '\' & @UserName & '\Favorites\*.*" "' & @FavoritesDir & '\*.*" /e /f /g /h /y /z > "Favorites_Restore.log"')
                sleep(500)
                _RunDOS('dir /s "' & @FavoritesDir & '" > "' & @ScriptDir & '\size.txt"')
                sleep(500)
                _FileReadToArray("size.txt", $size)
                sleep(500)
                $x = $size[0] - 2
                sleep(500)
                $size1 = StringStripWS($size[$x],3)
                sleep(500)
                FileWriteLine($backup_file, "--- Favorites --- <br>")
                sleep(500)
                FileWriteLine($backup_file, $size1 & ' <br>')
                sleep(500)
                FileWriteLine($backup_file, '<br>')
            EndIf
            sleep(500)
            if $Folders2 == "Signatures" Then
                GUICtrlSetData ( $text, 'Restoring the "Signatures" folder ' )
                sleep(500)
                _rundos( 'xcopy.exe "' & @ScriptDir & '\' & @UserName & '\Signatures\*.*" "' & @AppDataCommonDir & '\Microsoft\Signatures\*.*" /e /f /g /h /y /z > "Signatures_Restore.log"')
                sleep(500)
                _RunDOS('dir /s "' & @AppDataCommonDir & '\Microsoft\Signatures\" > "' & @ScriptDir & '\size.txt"')
                sleep(500)
                _FileReadToArray("size.txt", $size)
                sleep(500)
                $x = $size[0] - 2
                sleep(500)
                $size1 = StringStripWS($size[$x],3)
                sleep(500)
                FileWriteLine($backup_file, "--- Signatures --- <br>")
                sleep(500)
                FileWriteLine($backup_file, $size1 & ' <br>')
                sleep(500)
                FileWriteLine($backup_file, '<br>')
            EndIf
            sleep(500)
            if $Folders2 == "Notes Data" Then
                GUICtrlSetData ( $text, 'Restoring the "Notes Data" files ' )
                sleep(500)
                _rundos( 'xcopy.exe "' & @ScriptDir & '\' & @UserName & '\Notes Data\*.*" "' & @ProgramFilesDir & '\Notes\Data\*.*" /e /f /g /h /y /z > "Notes Data_Restore.log"')
                sleep(500)
                _RunDOS('dir /s "' & @ProgramFilesDir & '\Notes\Data" > "' & @ScriptDir & '\size.txt"')
                sleep(500)
                _FileReadToArray("size.txt", $size)
                sleep(500)
                $x = $size[0] - 2
                sleep(500)
                sleep(500)
                $size1 = StringStripWS($size[$x],3)
                sleep(500)
                FileWriteLine($backup_file, "--- Notes Data --- <br>")
                sleep(500)
                FileWriteLine($backup_file, $size1 & ' <br>')
                sleep(500)
                FileWriteLine($backup_file, '<br>')
            EndIf
            sleep(500)
            if $Folders2 == "SAPGui" Then
                GUICtrlSetData ( $text, 'Restoring the "SAP Gui" files ' )
                sleep(500)
                _rundos( 'xcopy.exe "' & @ScriptDir & '\' & @UserName & '\SAPGui\*.*" "' & @WindowsDir & '\*.*" /e /f /g /h /y /z > "SAPGui_Restore.log"')
                sleep(500)
                sleep(500)
                _RunDOS('dir /s "' & @ProgramFilesDir & '\Notes\Data" > "' & @ScriptDir & '\size.txt"')
                sleep(500)
                _FileReadToArray("size.txt", $size)
                sleep(500)
                $x = $size[0] - 2
                sleep(500)
                $size1 = StringStripWS($size[$x],3)
                sleep(500)
                FileWriteLine($backup_file, "--- Notes Data --- <br>")
                sleep(500)
                sleep(500)
                FileWriteLine($backup_file, $size1 & ' <br>')
                sleep(500)
                FileWriteLine($backup_file, '<br>')
            EndIf
            sleep(500)
            $Folders2 = ""
        Next
    EndIf
Edited by craig.gill

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

id suggets u look at smoke_ns lil UDF

http://www.autoitscript.com/forum/index.php?showtopic=36184

as i think it handles all files , and all in subfolders and such

example

#include <array.au3>
$file = @DesktopDir
$array = _FileListToArrayEx($file, "*.*", 0, '',True)
_ArrayDisplay($array, '')

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
    If Not FileExists($sPath) Then Return SetError(1, 1, '')
    If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
    If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
    Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
    For $iCC = 0 To 5
        If StringInStr($sFilter, $aBadChar[$iCC]) Or _
            StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
    Next
    If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead
    For $iCC = 1 To $aSplit[0]
        If StringStripWS($aSplit[$iCC], 8) = '' Then ContinueLoop
        If StringLeft($aSplit[$iCC], 1) = '.' And _
            UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
        Local $iPid
        If Not $iRecurse Then
            $iPid = Run(@ComSpec & ' /c ' & 'dir "' & $sPath & '\' & $aSplit[$iCC] & '" /b /o-e /od', '', @SW_HIDE, 6)
        Else
            $iPid = Run(@Comspec & ' /c dir /b /s /a "' & $sPath & '\' & $aSplit[$iCC] & '"', '', @SW_HIDE, 6)
        EndIf
        While 1
            $sRead &= StdoutRead($iPid)
            If @error Then ExitLoop
        WEnd
    Next
    If StringStripWS($sRead, 8) = '' Then Return SetError(4, 4, '')
    Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
    Local $sHold
    For $iCC = 1 To $aFSplit[0]
        If $sExclude And StringLeft(StringTrimLeft($aFSplit[$iCC], StringInStr($aFSplit[$iCC], '\', 0, -1)), _
            StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
        Switch $iFlag
            Case 0
                $sHold &= $aFSplit[$iCC] & Chr(1)
            Case 1
                If StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then ContinueLoop
                $sHold &= $aFSplit[$iCC] & Chr(1)
            Case 2
                If Not StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then ContinueLoop
                $sHold &= $aFSplit[$iCC] & Chr(1)
        EndSwitch
    Next
    If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(4, 4, '')
EndFunc
Edited by thatsgreat2345

Share this post


Link to post
Share on other sites

need a fresh set of eyes

consult a doctor...


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

id suggets u look at smoke_ns lil UDF

http://www.autoitscript.com/forum/index.php?showtopic=36184

as i think it handles all files , and all in subfolders and such

example

Thanks for the reply - the script only needs to find the name of the folders in the script directory and this is successfully completed - if you do a _arraydisplay it shows all folders listed ok . im just not sure why its skipping folders when comparing the names in the array.

Share this post


Link to post
Share on other sites

Thanks for the reply - the script only needs to find the name of the folders in the script directory and this is successfully completed - if you do a _arraydisplay it shows all folders listed ok . im just not sure why its skipping folders when comparing the names in the array.

im just saying that if you get all path names like said, and do an array and put it in a for next loop that does a _Pathsplit checks if the directory exists if it does not then it creates and and it would be much easier then using xcopy

Share this post


Link to post
Share on other sites

im just saying that if you get all path names like said, and do an array and put it in a for next loop that does a _Pathsplit checks if the directory exists if it does not then it creates and and it would be much easier then using xcopy

ok will give it a go

thanks

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0