I am in need of a script to search for all Microsoft word documents on a laptop hard drive and save a duplicate to a backup folder. I am aware of some apps that will do this but I am in a college setting and we can not afford shareware products. Thanks for any help. Using Panther.
This one is very quick, but it will overwrite documents with the same name:
set backupFolder to POSIX path of alias "disk:Users:john:Desktop:backup:"
do shell script "find / -name '*.doc' -exec echo 'cp "{}" "" & backupFolder & ""' \; | sh"
Or, to rename sequentially files with the same name, you can use this UNTESTED CODE:
global backupFolder
set backupFolder to POSIX path of alias "disk:Users:joe:Desktop:backup:"
set allDocs to (do shell script "find / -name '*.doc'")
set x to 1
repeat
try
my backupFile(allDocs's paragraph x)
set x to x + 1
on error --> no more stuff
exit repeat
end try
end repeat
to backupFile(f)
set fname to text 1 thru -5 of getName(f)
set increaseNumber to ""
repeat
try
alias ((backupFolder & fname & increaseNumber & ".doc") as POSIX file as text)
--> such file already exists, so...
set increaseNumber to increaseNumber + 1
on error --> such file doesn't exist
exit repeat
end try
end repeat
do shell script "cp " & quoted form of f & space & quoted form of (backupFolder & fname & increaseNumber & ".doc")
end backupFile
to getName(f)
set AppleScript's text item delimiters to "/"
set fname to item -1 of f's text items
set AppleScript's text item delimiters to {""}
fname
end getName