Jump to content

Desktop Tool


kpu
 Share

Recommended Posts

We are in the process of adding our PC's to the domain. I've writen a utility that will scan the users Desktop for files and copy the users favorites. The issue with my script is that it would copy folders and there contents. I know I could just use "xcopy" to do what I need, but I'm trying to learn here ... :wacko: So my code includes a progessbar to show what files are copied. Here's what I have.

Here's the code. I've have many of these sections for every kind of file extention I want to copy.

;--------------------------------------------------------------------------------------
;                                   Find and copy *.doc
;--------------------------------------------------------------------------------------
$e = 6
$backup_dir = $path & "\Documents"
DirCreate($backup_dir)
If FileExists($backup_dir) Then
    $file_name = "Word Documents"
    $extension = "*.doc"
    $location = @UserProfileDir & "\Desktop\"
    $file_path = @UserProfileDir & "\Desktop\" & $extension
    _cpCommand()
Else
EndIf

Here's what my functions look like. This is where I need help coping the folder contents.

Func _cpCommand()
    $search = FileFindFirstFile($file_path)
    If $search = -1 Then
        ProgressSet($e, "Coping " & $file_name, "Copying " & $extension & " to F:\ Drive")
    ;MsgBox(0, "Information", "No files where found containing " & $extension)
        _FileWriteLog($logFile, "No files where found containing " & $extension)
    Else
        $i = 0
        While 2
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            $i = $i + 1
        ;MsgBox(4096, "File:", $location & $file & " To " & $backup_dir & "\" & $file)
            ProgressSet($e, "Coping " & $file, "Copying " & $file_name & " to F:\ Drive")
            FileCopy($location & $file, $backup_dir & "\" & $file)
            _FileWriteLog($logFile, "Copied " & $location & $file & " To " & $backup_dir & "\" & $file)
        WEnd
        FileClose($search)
        MsgBox(32, "File Copy", "You had a tolal of " & $i & " " & $file_name & " found and copied",2)
    EndIf
EndFunc  ;==>_cpCommand
Edited by kpu
Link to comment
Share on other sites

I had the same task some time ago. Needed a quick and easy way to backup and/or restore all the user's important data to/from their home share. Used routinely, the incrementals are very quick. I have two versions, one for networked users and one for use with an external drive. I've attached the source and compiled script for the network version.

You can find the other version (external drive) here:

http://www.autoitscript.com/forum/index.ph...ndpost&p=118617

To recompile without error, put robocopy.exe in a folder named PUBLIC off your root. (c:\public\robocopy.exe)

robobkup.zip

Edited by gspino
Link to comment
Share on other sites

Thanks for the script. I know there are many ways to do this and very easy ways as well. I'll just stop trying to make it harder then it needs to be. Thanks for looking at the "robocopy.exe" in resouce kit. That should work great.

B)

There are no wasted efforts in script writing, you're either learning something new or reinforcing what you already know. When I look at a project such as yours, I tend to try and make the script as versitile as possible. In this case, I chose Robocopy for it's speed and flexibility and scripted a wrapper around it - it gave me what I needed as a domain admin and it gave the user's a tool at the same time.

-Glen

BTW, I also wrote a wrapper for psexec - to allow me, as a domain admin, to launch my scripts on a remote workstation while the user is logged in.

http://www.autoitscript.com/forum/index.ph...ndpost&p=119507

Edited by gspino
Link to comment
Share on other sites

Okay.. I think I'm getting closer. I'm just lost on tring to get $location[$x] to work. Could someone look to see if I'm doing this right.

#include <file.au3>
$path = "F:\" & @ComputerName
$logFile = $path & "\CopyTo.log"
$sfile = "contents.txt"
$e = 0
Dim $extension, $location, $file, $dest, $file_path, $file_name, $backup_dir,$Wfile,$sFile,$x

For $x = 1 to $location[0]
;--------------------------------------------------------------------------------------
;                                   Find and copy *.doc
;--------------------------------------------------------------------------------------
$e = 6
$backup_dir = $path & "\Documents"
DirCreate($backup_dir)
If FileExists($backup_dir) Then
    $file_name = "Word Documents"
    $extension = "*.doc"
    $location[$x]= @UserProfileDir & "\Desktop\"
    $file_path = @UserProfileDir & "\Desktop\" & $extension
    _cpCommand()
Else
EndIf
;--------------------------------------------------------------------------------------
;                                   Find and copy *.rtf
;--------------------------------------------------------------------------------------
$e = 7
$backup_dir = $path & "\Documents"
DirCreate($backup_dir)
If FileExists($backup_dir) Then
    $file_name = "Rich text Documents"
    $extension = "*.rtf"
    $location[$x]= @UserProfileDir & "\Desktop\"
    $file_path = @UserProfileDir & "\Desktop\" & $extension
    _cpCommand()
Else
EndIf
;--------------------------------------------------------------------------------------
;                                   Find and copy *.dot
;--------------------------------------------------------------------------------------
$e = 9
$backup_dir = $path & "\Documents"
DirCreate($backup_dir)
If FileExists($backup_dir) Then
    $file_name = "Word Documents"
    $extension = "*.dot"
    $location[$x]= @UserProfileDir & "\Desktop\"
    $file_path = @UserProfileDir & "\Desktop\" & $extension
    _cpCommand()
Else
EndIf
Next




Func _cpCommand()
    $search = FileFindFirstFile($file_path)
    If $search = -1 Then
        ProgressSet($e, "Coping " & $file_name, "Copying " & $extension & " to F:\ Drive")
    ;MsgBox(0, "Information", "No files where found containing " & $extension)
        _FileWriteLog($logFile, "No files where found containing " & $extension)
    Else
        $i = 0
        While 2
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            $i = $i + 1
        ;MsgBox(4096, "File:", $location[$x]& $file & " To " & $backup_dir & "\" & $file)
            ProgressSet($e, "Coping " & $file, "Copying " & $file_name & " to F:\ Drive")
            FileCopy($location[$x]& $file, $backup_dir & "\" & $file)
            _FileWriteLog($logFile, "Copied " & $location[$x]& $file & " To " & $backup_dir & "\" & $file)
        WEnd
        FileClose($search)
        MsgBox(32, "File Copy", "You had a tolal of " & $i & " " & $file_name & " found and copied",2)
    EndIf
EndFunc  ;==>_cpCommand 

Func _WriteFileContents($sFile)
    $Wsearch = FileFindFirstFile($location[$x]& $Wfile & "*.*")
    If $Wsearch = -1 Then
        MsgBox(0, "Error", "No files/directories matched the search pattern")
        Exit
    EndIf
    While 1
        $Wfile = FileFindNextFile($Wsearch)
        If @error Then ExitLoop
        $xfile = _IsFolder($location[$x]& $Wfile)
        If $xfile = "1" Then
            If $Wfile = "." Then
            ElseIf $Wfile = ".." Then
            Else
                FileWriteLine($sFile, $Wfile)
            ;MsgBox(32, "xfile", $Wfile & " is " & $xfile)
            EndIf
        Else
        EndIf
    WEnd
    FileClose($Wsearch)
EndFunc  ;==>_WriteFileContents

Func _errorCtl();This is used for error control.
    If UBound(ProcessList(@ScriptName)) > 2 Then
        $run2 = MsgBox(164, "Warning", "Application is already running!")
        Exit
    Else
    EndIf
EndFunc  ;==>_errorCtl

Func _cpCommand2()
    $cpfile = FileOpen($sFile, 0)
    If $cpfile = -1 Then
        MsgBox(0, "Error on CpCommand2", "Unable to open file." & $sFile)
        Exit
    EndIf
    While 1
    $cpline = FileReadLine($cpfile)
    $location[0] = @UserProfileDir & "\Desktop\" & $cpline
    _CopyFilesToNetwork()
    Wend
    FileClose($cpfile)
EndFunc  ;==>_cpCommand 

Func _IsFolder( $sPath )
    If not FileExists($sPath) Then SetError(1)
    Return not not StringInStr(FileGetAttrib($sPath), "D")
EndFunc
Link to comment
Share on other sites

How many different $location are you expecting?

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

How many different $location are you expecting?

It all depends on how many directorys it finds. How the code is suppose to work is this:

1. Runs Function _WriteFileContents which writes to a file all the directories it finds.

2. Runs the the multipule searchs on file extentions running _cpCommand()

3. Then runs _cpCommand2() that reads the file that _WriteFileContents created and repeats until the end of the file.

Make sense?

I would assume most people only have a few folders at my place of employment.

Link to comment
Share on other sites

It seams to me that you need to have something run that will give you a count of the total number of $locations you are going to be working with. Then you need to do dimention the array ($location) accordingly.

This has to happen before the script gets to your main For-Next loop.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Perhaps it would help if you outlined the process you are picturing. Pseudo Code is very helpfull in troubleshooting issues like this.

Something like:

Find all sub folders under C:\xyz

Make a folder called F:\"username"

Start loop

Find all .doc under C:\xyz\(first subdir found)

Copy all .doc to f:\"username"\docs\

find all .rtf under C:\xyz\(first subdir found)

Copy all .rtf to f:\"username"\rtfs\

find all .dot under C:\xyz\(first subdir found)

Copy all .dot to f:\"username"\dots\

End loop

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Picture:

1. Scan desktop for File extention(s), then do the following:

  • Update Progress bar
  • Copy file
  • Write Log of how many files it found'
2. If Folder is found, update $location and run Step 1 Again.

Below is the updated, stripted down code:

Getting the following error:

F:\0.Programs\0-ProfileCopier\TESTING\ContentList.au3 (33) : ==> Subscript used with non-Array variable.:

$search = FileFindFirstFile($location[$x]& $Wfile & "*.*")

$search = FileFindFirstFile($location^ ERROR

Dim $logFile, $IsDir, $Wfile, $xfile, $location
#include <file.au3>
DirCreate("F:\" & @ComputerName)
$path = "F:\" & @ComputerName
$logFile = $path & "\CopyTo.log"
$sfile = "contents.txt"
FileDelete($sfile)
_WriteFileContents("Contents.txt")
If Not _FileReadToArray($sfile, $location) Then
    MsgBox(4096, "Error", " Error reading log to Array   error:" & @error)
    Exit
EndIf
For $x = 1 To $location[0]
    MsgBox(0, 'Record:' & $x, $location[$x])
    _cpCommand2()
Next
Func _CopyFilesToNetwork()
;--------------------------------------------------------------------------------------
;                                   Find and copy *.doc
;--------------------------------------------------------------------------------------
    $e = 6
    $backup_dir = $path & "\Documents"
    DirCreate($backup_dir)
    If FileExists($backup_dir) Then
        $Wfile_name = "Word Documents"
        $extension = "*.doc"
        $location[$x] = @UserProfileDir & "\Desktop\"
        $Wfile_path = @UserProfileDir & "\Desktop\" & $extension
    Else
    EndIf
EndFunc  ;==>_CopyFilesToNetwork
Func _WriteFileContents($sfile)
    $search = FileFindFirstFile($location[$x] & $Wfile & "*.*")
    If $search = -1 Then
        MsgBox(0, "Error", "No files/directories matched the search pattern")
        Exit
    EndIf
    While 1
        $Wfile = FileFindNextFile($search)
        If @error Then ExitLoop
        $xfile = _IsFolder($location[$x] & $Wfile)
        If $xfile = "1" Then
            If $Wfile = "." Then
            ElseIf $Wfile = ".." Then
            Else
                FileWriteLine($sfile, $Wfile)
            ;MsgBox(32, "xfile", $Wfile & " is " & $xfile)
            EndIf
        Else
        EndIf
    WEnd
    FileClose($search)
EndFunc  ;==>_WriteFileContents
Func _cpCommand2()
    $cpfile = FileOpen($sfile, 0)
    If $cpfile = -1 Then
        MsgBox(0, "Error on CpCommand2", "Unable to open file." & $sfile)
        Exit
    EndIf
    While 1
        $cpline = FileReadLine($cpfile)
        $location[$x] = @UserProfileDir & "\Desktop\" & $cpline
        _CopyFilesToNetwork()
    WEnd
    FileClose($cpfile)
EndFunc  ;==>_cpCommand2
Func _IsFolder($sPath)
    If Not FileExists($sPath) Then SetError(1)
    Return Not Not StringInStr(FileGetAttrib($sPath), "D")
EndFunc  ;==>_IsFolder

Does that help?

Link to comment
Share on other sites

I might have done it like this:

$desktop = @UserProfileDir & "\Desktop\"
$dest = "H:\" & @UserName

; Run through the directory once to find out how many files there are
DirCreate($dest)
$search = FileFindFirstFile($desktop & "*.*")
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories found")
    Exit
EndIf
$count = 0
While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop;continue until there are no more items
    $attrib = FileGetAttrib($desktop & $file)
    If Not StringInStr($attrib, "D") Then ; If not a directory
        $count = $count + 1
    EndIf
WEnd
FileClose($search)


; Run through it again copying each non-directory file to the destination folder
ProgressOn("Copying " & $count & " files", "Please stand by")
$search = FileFindFirstFile($desktop & "*.*")
$count2 = 0
While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop;continue until there are no more items
    $attrib = FileGetAttrib($desktop & $file)
    If Not StringInStr($attrib, "D") Then ; If not a directory
        $count2 = $count2 + 1
        $percent = Int($count2 / $count * 100)
        ProgressSet($percent, $percent & "% complete", $file)
        FileCopy($desktop & $file, $dest, 1)
    EndIf
WEnd

FileClose($search)
ProgressOff()

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Ah I misunderstood. I thought you wanted to avoid directories.

So you want to copy everything on the desktop (including subdirs) to a folder somewhere else?

You want to progress bar to increment all the way through the process.

Do you want a specific list of what was moved? or just a total number of files? or did you want [X docs, X dots, X rtfs]?

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Yup, all the above.

I'm trying to have it write a log of all files it copies, just to verify that it did what it was suppose to.

Ah I misunderstood. I thought you wanted to avoid directories.

So you want to copy everything on the desktop (including subdirs) to a folder somewhere else?

You want to progress bar to increment all the way through the process.

Do you want a specific list of what was moved? or just a total number of files? or did you want [X docs, X dots, X rtfs]?

Link to comment
Share on other sites

Check out:

http://www.autoitscript.com/forum/index.ph...topic=16421&hl=

I'll try to throw something together that suits your needs if I get some time

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Check out:

http://www.autoitscript.com/forum/index.ph...topic=16421&hl=

I'll try to throw something together that suits your needs if I get some time

Thanks for the link! Don't worry about coding something for me unless you really want to. I think I have what I need with the link you sent me.

Thanks for all your help with this! B)

Link to comment
Share on other sites

Also look at Larry's FileProgressCopy, it may be even more what you are looking for:

http://www.autoitscript.com/forum/index.ph...wtopic=4973&hl=

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Thanks for all your Help. Here is the Final WORKING project. B)

#include <File.au3>
Dim $ext, $x
$bkupDir = "f:\" & @ComputerName
$fsource = @UserProfileDir & "\Desktop\"
$fileDest = $bkupDir & "\Documents"
$FavSource = @UserProfileDir & "\Favorites\"
$favDest = $bkupDir & "\Favorites"
FileInstall("Extensions.txt","Extensions.txt",1)
$extFile = "Extensions.txt"
;--------------------------------------------------------------------------------------
;                                      Code
;--------------------------------------------------------------------------------------
_errorCtrl()
If FileExists($bkupDir) Then
    If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(36, "Restore", "Would you like to restore your favorites?")
    Select
        Case $iMsgBoxAnswer = 6;Yes
            _RestoreBackupFav()
            MsgBox(32, "Successful", "Your Favorites have been restored")
        Case $iMsgBoxAnswer = 7;No
    EndSelect
Else
    If Not IsDeclared("iMsgBoxbackup") Then Dim $iMsgBoxbackup
    $iMsgBoxbackup = MsgBox(36, "Backup?", "Would you like to backup the files on your desktop and your Favorites?")
    Select
        Case $iMsgBoxbackup = 6;Yes
            _BackItUp($bkupDir)
            MsgBox(32, "Successful", "Your Files have been backed up")
            FileDelete($extFile)
        Case $iMsgBoxbackup = 7;No
    EndSelect
EndIf
;--------------------------------------------------------------------------------------
;                                   Functions
;--------------------------------------------------------------------------------------
Func _errorCtrl();This is used for error control.
    If UBound(ProcessList(@ScriptName)) > 2 Then
        $run2 = MsgBox(164, "Warning", "Application is already running!")
        Exit
    Else
    EndIf
    If FileExists("Extensions.txt") Then
    Else 
        MsgBox(16,"Warning!","Couldn't load Extentions to search for! " & $extFile)
        Exit
    EndIf
EndFunc  ;==>_errorCtl
Func _RestoreBackupFav()
    _FileProgressCopy($favDest & "\*.url", @UserProfileDir & "\Favorites\", 1)
EndFunc  ;==>_RestoreBackupFav
Func _BackItUp($bkLocation)
    If FileExists($bkupDir) Then
        _FindAndCopyFiles()
        _FileProgressCopy($FavSource & "*.url", $favDest, 1)
    Else
        DirCreate($bkupDir)
        DirCreate($favDest)
        _FindAndCopyFiles()
    EndIf
EndFunc  ;==>_BackItUp
Func _FindAndCopyFiles()
;$extFile = location of file that has the extentions in it.;; *.ext
    If Not _FileReadToArray("Extensions.txt", $ext) Then
        MsgBox(4096, "Error", @error & " Unable to open Extensions.txt")
        Exit
    EndIf
    For $x = 1 To $ext[0]
        _FileProgressCopy($fsource & $ext[$x], $fileDest, 1)
    Next
EndFunc  ;==>_FindAndCopyFiles
Func _FileProgressCopy($szMask, $szDest, $nOption)
; _FileProgressCopy( <Path and Mask>, <Destination>,<Option (0 - normal, 1- recursive)>)
    If StringRight($szDest, 1) <> "\" Then $szDest = $szDest & "\"
    ProgressOn("File Copy In Progress", "Creating File List","","","",16)
    ProgressSet(5)
    $aFiles = _FileSearch($szMask, $nOption)
    If $aFiles[0] Then
        ProgressSet(0, "", "Serching for files...")
        If Not StringInStr($szMask, "\") Then
            $szRoot = @ScriptDir & "\"
        Else
            $szRoot = StringLeft($szMask, StringInStr($szMask, "\", 0, -1))
            $szMask = StringTrimLeft($szMask, StringInStr($szMask, "\", 0, -1))
        EndIf
        For $i = 1 To $aFiles[0]
            $n = StringInStr(FileGetLongName($aFiles[$i]), FileGetLongName($szRoot) & "\")
            If $n Then
                $szDestFile = $szDest & StringReplace(FileGetLongName($aFiles[$i]), FileGetLongName($szRoot) & "\", "")
            Else
                $szDestFile = $szDest & StringTrimLeft(FileGetLongName($aFiles[$i]), 3)
            EndIf
            If Not FileExists(StringLeft($szDestFile, StringInStr($szDestFile, "\", 0, -1))) Then _
                    DirCreate(StringLeft($szDestFile, StringInStr($szDestFile, "\", 0, -1)))
            ProgressSet(Int(100 * ($i / $aFiles[0])), "Copying " & $aFiles[$i])
            FileCopy($aFiles[$i], $szDestFile)
            _FileWriteLog("CopiedFiles.log", "Copied:" & $aFiles[$i] & " To:" & $szDestFile)
        Next
    EndIf
EndFunc  ;==>_FileProgressCopy
Func _FileSearch($szMask, $nOption)
    $szRoot = ""
    $hFile = 0
    $szBuffer = ""
    $szReturn = ""
    $szPathList = "*"
    Dim $aNULL[1]
    If Not StringInStr($szMask, "\") Then
        $szRoot = @ScriptDir & "\"
    Else
        $szRoot = StringLeft($szMask, StringInStr($szMask, "\", 0, -1))
        $szMask = StringTrimLeft($szMask, StringInStr($szMask, "\", 0, -1))
    EndIf
    If $nOption = 0 Then
        _FileSearchUtil($szRoot, $szMask, $szReturn)
    Else
        While 1
            $hFile = FileFindFirstFile($szRoot & "*.*")
            If $hFile >= 0 Then
                $szBuffer = FileFindNextFile($hFile)
                While Not @error
                    If $szBuffer <> "." And $szBuffer <> ".." And _
                            StringInStr(FileGetAttrib($szRoot & $szBuffer), "D") Then _
                            $szPathList = $szPathList & FileGetShortName($szRoot & $szBuffer) & "*"
                    $szBuffer = FileFindNextFile($hFile)
                WEnd
                FileClose($hFile)
            EndIf
            _FileSearchUtil($szRoot, $szMask, $szReturn)
            If $szPathList == "*" Then ExitLoop
            $szPathList = StringTrimLeft($szPathList, 1)
            $szRoot = StringLeft($szPathList, StringInStr($szPathList, "*") - 1) & "\"
            $szPathList = StringTrimLeft($szPathList, StringInStr($szPathList, "*") - 1)
        WEnd
    EndIf
    If $szReturn = "" Then
        $aNULL[0] = 0
        Return $aNULL
    Else
        Return StringSplit(StringTrimRight($szReturn, 1), "*")
    EndIf
EndFunc  ;==>_FileSearch
Func _FileSearchUtil(ByRef $ROOT, ByRef $MASK, ByRef $RETURN)
    $hFile = FileFindFirstFile($ROOT & $MASK)
    If $hFile >= 0 Then
        $szBuffer = FileFindNextFile($hFile)
        While Not @error
            If $szBuffer <> "." And $szBuffer <> ".." Then _
                    $RETURN = $RETURN & $ROOT & $szBuffer & "*"
            $szBuffer = FileFindNextFile($hFile)
        WEnd
        FileClose($hFile)
    EndIf
EndFunc  ;==>_FileSearchUtil

Thanks to SpookMeister and Larry!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...