Extracting documents from folders and subfolders

Ok, here is my situation. I have a number of Quark documents that have been flightchecked. For those who don’t know, that means that each page has been collected with all its images and fonts into a separate folder. All of these folders are together in another folder. I need to extract a copy of each of the Quark documents into another folder without their accompanying images, fonts, etc.

Below is the script I have created.


set theFolder to choose folder with prompt "Please select the folder to collect from..."
tell application "Finder"
	activate
	if not (folder "Quark Docs" of theFolder exists) then
		set newFolder to make new folder at theFolder with properties {name:"Quark Docs"}
		set outFolder to newFolder
	else
		set newFolder to folder "Quark Docs" --at theFolder
		set outFolder to newFolder as alias
	end if
end tell

parseFolder(theFolder)

on parseFolder(aFolder)
	tell application "Finder"
		set theNumItems to number of items in aFolder
		set listOfItems to the name of every item in aFolder
	end tell
	
	repeat with i from 1 to theNumItems
		tell application "Finder"
			set anItem to item i of aFolder
			if kind of anItem = "folder" then
				set continueProc to true
			else
				set continueProc to false
				if creator type of anItem = "XPR3" then
					duplicate anItem to outFolder --******
				end if
			end if
		end tell
		
		if continueProc = true and name of anItem is not "Quark Docs" then
			parseFolder(anItem)
		end if
	end repeat
end parseFolder


On the line indicated above with the ****** I get an error whenever the Quark Docs folder already exists in theFolder. I don’t understand why. I can just make sure that there is no folder by that name when I start, but I would like to know why I get the error.

Jmax

Hi…
You must call the recursive subroutine in the loop…

on parseFolder(aFolder) 
   tell application "Finder" 
      set theNumItems to number of items in aFolder 
      set listOfItems to the name of every item in aFolder 
   end tell 
   repeat with i from 1 to theNumItems 
      tell application "Finder" 
         set anItem to item i of aFolder 
         if kind of anItem = "folder" and name of anItem is not "Quark Docs" then 
            parseFolder(anItem) 
         else 
            if creator type of anItem = "XPR3" then 
               duplicate anItem to outFolder 
            end if 
         end if 
      end tell 
   end repeat 
end parseFolder 

or, another idea with coping every XPress files at same time :

global ListXPDoc, outFolder

on run
	set ListXPDoc to {}
	set theFolder to choose folder with prompt "Please select the folder to collect from..."
	tell application "Finder"
		activate
		if not (folder "Quark Docs" of theFolder exists) then
			set outFolder to make new folder at theFolder with properties {name:"Quark Docs"}
		else
			set outFolder to (folder "Quark Docs" of theFolder) as alias
		end if
	end tell
	parseFolder(theFolder) of me
end run

on parseFolder(aFolder)
	tell application "Finder"
		set ListFolders to every folder of aFolder whose name is not "Quark Docs"
		repeat with ItemFolder in ListFolders
			if kind of ItemFolder is not "folder" then
				set end of ListXPDoc to (every file of ItemFolder whose creator type is "XPR3")
			else
				parseFolder(ItemFolder) of me
			end if
		end repeat
		duplicate every item of ListXPDoc to outFolder
	end tell
end parseFolder

Sorry, a big bug in my last idea :frowning:

Here a clean code :wink:

global ListXPDoc, outFolder
on run
	set ListXPDoc to {}
	set theFolder to choose folder with prompt "Please select the folder to collect from..."
	tell application "Finder"
		activate
		if not (folder "Quark Docs" of theFolder exists) then
			set outFolder to make new folder at theFolder with properties {name:"Quark Docs"}
		else
			set outFolder to (folder "Quark Docs" of theFolder) as alias
		end if
	end tell
	parseFolder(theFolder) of me
end run
on parseFolder(aFolder)
	tell application "Finder"
		set ListFolders to every folder of aFolder whose name is not "Quark Docs"
		repeat with ItemFolder in ListFolders
			set end of ListXPDoc to (every file of ItemFolder whose creator type is "XPR3")
			if (count folders in ItemFolder) > 0 then parseFolder(ItemFolder) of me
		end repeat
		duplicate every item of ListXPDoc to outFolder
		set ListXPDoc to {}
	end tell
end parseFolder

I think this is the part that needs attention:

else 
       set newFolder to folder "Quark Docs" --at theFolder 
       set outFolder to newFolder as alias

It looks like you are attempting to make an alias out of a folder name. You need to either provide a path or Finder reference.