Hi… I have directories which contain tons of .GZ & .zip files which I wanted to create a script to do so…
However, I also found that within these directories are a lot of subdirectories also containing lots of .GZ & .zip files… so this is my first useful script that I created:
set x to 0 --the number of files extracted
set y to 0 --the number of folders deleted
set folderDefinition to (choose folder with prompt “Collins Anti-GZIP & ZIP script” without invisibles)
set folderString to (folderDefinition as string)
tell application “Finder”
open alias folderString
set numfolders to the name of every folder in front window
set folderCount to (count numfolders)
if folderCount > 1 then
set buttonResponse to the button returned of (display dialog "Move out all files from the " & folderCount & " subdirectories found in " & folderString & "?" buttons {"Yes", "No"} default button 1)
end if
if folderCount = 1 then
set buttonResponse to the button returned of (display dialog "Move out all files from the " & folderCount & " subdirectory found in " & folderString & "?" buttons {"Yes", "No"} default button 1)
end if
if buttonResponse = "Yes" then
repeat with curDir in numfolders
set curString to (curDir as string)
if curString ? "oldzips" then
set curLocation to folderString & curString
--display dialog "copying " & curLocation & " to " & folderString
move every file of the folder curLocation to the folder folderString
delete the folder curLocation
end if
set y to y + 1
end repeat
end if
beep
display dialog "" & y & " Folders deleted and their contents were emptied to " & folderString
if not (the folder "oldzips" of folderDefinition exists) then
make new folder in folderDefinition with properties {name:"oldzips"}
end if
set noFiles to every file in front window
repeat with curFile in noFiles
(* this was to delete files unzipped files
if the name of curFile contains ".dsk" and the name of curFile does not contain ".dsk." then
delete curFile
end if *)
if the name of curFile contains ".gz" then
set curString to (curFile as string)
tell application "StuffIt Expander"
expand the file curString
end tell
move the file curString to the folder "oldzips" of folderDefinition
set x to x + 1
else if the name of curFile contains ".zip" then
set curString to (curFile as string)
tell application "StuffIt Expander"
expand the file curString
end tell
move the file curString to the folder "oldzips" of folderDefinition
set x to x + 1
end if
end repeat
end tell
beep
display dialog “You have successfully converted " & x & " files.”
-------- END OF SCRIPT ------------
So… my question is, does anyone have any suggestions on how I could easily make this recursive so that the first section (involving y) will see folders within folders within folders?
Secondly… I am finding that I still have some .gzip files but they don’t have a .gz extention… So should I be operating off of a filetype/creator comparison rather than “.gz” and “zip”?
and Finally… If I run this script and it creates the folder “oldzips”, when I run it a second time, it will see this folder and ask if I want to empty its contents (which I don’t)… Is there an easy way to say:
set numfolders to the name of every folder in front window EXCEPT for “oldzips”
??
also, is there a way to GOTO a place within a script without using subroutines? Like a way to say:
beginning:
set x to “10”
set x to x - 1
display dialog X
go to beginning
???
Or is the best way to accomplish this with repeat and end repeat? (is there a repeat for infinity?)
further, any suggestions on how I could be more efficient with my scripting?
thanks so much!!!