Sign in to follow this  
Followers 0
ragemxf

Need to search files...then copy resulted files

13 posts in this topic

I am trying to get a script that will first: search all c: for .pst and .pab

then I want it to copy resulted files to a network location....

this is basically a backup script for when I am changing out 30 pc's at a time...

Is this even possible?

Neal Smith

Share this post


Link to post
Share on other sites



I am trying to get a script that will first: search all c: for .pst and .pab

then I want it to copy resulted files to a network location....

this is basically a backup script for when I am changing out 30 pc's at a time...

Is this even possible?

Neal Smith

<{POST_SNAPBACK}>

You have already seen the answer in Scrips and Scraps


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

I have being looking for the same thing for more than 5 hours, but can't find anything like it.

Does anyone know the link to a script that would do that?

Share this post


Link to post
Share on other sites

I have being looking for the same thing for more than 5 hours, but can't find anything like it.

Does anyone know the link to a script that would do that?

I don't know link for backup scripts

but look into Autoit Helpfile at these functions:

FileCopy()

_FileListToArray() - no recurse

For recurse searching search forum for:

_FileSearch()

_FileListToArrayEx()

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try this- it should write a log of what is backed up as well..

CODE
#include <file.au3>

#include <array.au3>

#include <date.au3>

Dim $FileList[1], $backupdest, $Searchdest, $log

;Backup Destination (dont forget trailing backslash)

$backupdest = "C:\backuptest\"

;Search dest (no trailing backslash)

$Searchdest = "C:"

_ArrayInsert($FileList, 1, "These files were backed up on " & _Now())

$log = Search($Searchdest)

;Write a log.

FileWrite($backupdest & "backuplog.log", $log)

Exit

Func Search($current)

Local $search = FileFindFirstFile($current & "\*.*")

While 1

Dim $file = FileFindNextFile($search)

If @error Or StringLen($file) < 1 Then ExitLoop

;Add pst / pab files to the array and backup

If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") And StringRight($file, 3) = "pst" or StringRight($file, 3) = "pab" Then

_ArrayAdd($FileList,$current & "\" & $file)

FileCopy($current & "\" & $file, $backupdest & $file)

EndIf

If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then

Search($current & "\" & $file)

EndIf

WEnd

FileClose($search)

$string = _ArrayToString($FileList, @CR)

$string = StringReplace($String, @CR, @CRLF)

Return($string)

EndFunc

-John

Edited by JSunn

Share this post


Link to post
Share on other sites

Thank you, just one more request if possible, My HD has two partitions, D and E how can I extend the search to those two drives?

Share this post


Link to post
Share on other sites

Thank you, just one more request if possible, My HD has two partitions, D and E how can I extend the search to those two drives?

Call your search function twice (so you will have two arrays) and merge two output arrays.

$array1 = SomeSearch('C:\*.*')
$array2 = SomeSearch('D:\*.*')

; merge arrary1 and array2 using standard array UDF _ArrayAdd()
; ...

Share this post


Link to post
Share on other sites

I haven't work with arrays too much, can you show me how to do it?

Share this post


Link to post
Share on other sites

Call your search function twice (so you will have two arrays) and merge two output arrays.

$array1 = SomeSearch('C:\*.*')
$array2 = SomeSearch('D:\*.*')

; merge arrary1 and array2 using standard array UDF _ArrayAdd()
; ...
Here is a modified script.. read the code comments to understand. Previously I was writing all the files into an array and then writing that to a log file to a backup log. I removed the array and replaced it with the _FileWriteLog function. one thing to keep in mind.. This is not a full backup solution. There is no date modified checking to see which file is newer. If the file already exists in the destination then it will NOT be copied. You can figure out how to add this feature yourself Im sure.

CODE
#include <file.au3>

#include <array.au3>

#include <date.au3>

Dim $FileList[1], $backupdest, $Searchdest, $log

;Backup Destination (dont forget trailing backslash)

$backupdest = "C:\backuptest\"

;Write Search([driveletter or folder]) to be searched for files.

Search("C:")

Search("D:")

Search("E:")

Exit

Func Search($current)

Local $search = FileFindFirstFile($current & "\*.*")

While 1

Dim $file = FileFindNextFile($search)

If @error Or StringLen($file) < 1 Then ExitLoop

;Add pst / pab files to the array and backup

If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") and Not StringInStr($current & "\" & $file, $backupdest) And ($file <> "." Or $file <> "..") And StringRight($file, 3) = "pst" or StringRight($file, 3) = "pab" Then

$result = FileCopy($current & "\" & $file, $backupdest & $file)

;Write to log file. Keep in mind many files cannot be copied if they are the same name but different versions because they are

;all being copied into the destination.

If $result = 1 Then

_FileWriteLog($backupdest & "backuplog.log", "BACKUP SUCCESS: " & $current & "\" & $file)

Else

_FileWriteLog($backupdest & "backuplog.log", "BACKUP FAILURE: " & $current & "\" & $file)

Endif

EndIf

If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") AND StringInStr($current & "\" & $file, $backupdest) = 0 Then

Search($current & "\" & $file)

EndIf

WEnd

FileClose($search)

EndFunc

Share this post


Link to post
Share on other sites

Yes I can, Thank you for teaching me.

Share this post


Link to post
Share on other sites

Yes I can, Thank you for teaching me.

You are welcome. For date / time comparison you might want to use FileGetTime("C:\backupfile.txt", 1, 1) and compare it to FileGetTime("C:\destfile.txt", 1, 1) - this coverts the date / time into an number that can be added or subtracted to see which one is newer, etc... I am interested in seeing what you come up with.

Share this post


Link to post
Share on other sites

I'll post the final code latter, something just ocurred to me, what if there's a directory I want to exclude from my search, how can I do that?

For example if I'm looking for PDF documents, I don't want to look in the programs directory, becouse most programs create a help or how to guide in PDF format, I could get a lot of unnecesary hits if I don't exclude it.

Any help or pointers please.

Share this post


Link to post
Share on other sites

I'll post the final code latter, something just ocurred to me, what if there's a directory I want to exclude from my search, how can I do that?

For example if I'm looking for PDF documents, I don't want to look in the programs directory, becouse most programs create a help or how to guide in PDF format, I could get a lot of unnecesary hits if I don't exclude it.

Any help or pointers please.

Instead of adding exclusions, I suggest you limit your search. For example, the pst and pab files you are looking to backup usually exist somewhere in a users profile under C:\Document and Settings\username\.. Try limiting your search to a specific parent folder. To do that you just change it from

Search("C:")

to

Search("C:\Documents and Settings")

remember you can search as many different folders as you like

example:

Search("C:\Documents and Settings")

Search("C:\WIndows")

Search(C:\Temp")

Hope this helps

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