• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Duplicate instead of Delete files in the list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Duplicate instead of Delete files in the list


  • Subject: Duplicate instead of Delete files in the list
  • From: Nellyann Rosario <email@hidden>
  • Date: Tue, 29 Dec 2009 15:07:01 -0500
  • Thread-topic: Duplicate instead of Delete files in the list

Title: Duplicate instead of Delete files in the list
An apple script guru wrote this script but this time instead deleting files without any warning & I would like to duplicate the items found in the list & put them into a new folder. I know it is possible but I don't know how do it. Can someone help me please ;-)

--use mdfind to find all files that contain letter codes
set
lookInThisFolderOnly to choose folder with prompt "Choose folder that has images to delete"
set
logFolderPath to (choose folder with prompt "Choose a place to write the log") as string
set lookInThisFolderOnly to (POSIX path of lookInThisFolderOnly)

set theCodeList to {"AVI", "BWD", "CAK", "CRH", "CXP", "DWE", "EDB", "FSA", "FSF", "GMM ", "HCC", "HEC", "HMS", "HSL", "HWP", "HYA", "KAA", "KAO", "MCU", "MDS", "MEM", "MFC", "MHG", "MKB", "MMB", "MPU", "MSK", "MSW", "MUZ", "NPC", "NPC", "NVW", "NVW", "ORL", "ORL", "PGN", "PMT", "QDV", "RRQ", "RRQ", "RYG", "SCT", "SGV", "SHN", "SLA", "SVY", "SXP", "VNE", "VNE", "WLR", "WMH", "WPV", "WRF", "ZUS", "ZVL"}
repeat
with aCode in theCodeList
   set theMDFindScript to "mdfind -onlyin " & lookInThisFolderOnly & " kMDItemDisplayName == '*" & (aCode as string) & "*'"
   set theList to (do shell script theMDFindScript)
   
    
if theList ≠ "" then
       tell me to writeToFile({rpText:("- Files Deleted - " & return & theList & return), rpDest:logFolderPath, rpFileName:"DeleteFiles.log", opAppend:"a", opTimeStamp:"f"})
       set AppleScript's text item delimiters to return
       set theList to every text item of theList
       tell me to deleteFileFolder({rpTarget:theList})
   end if
end
repeat




--===========DeleteFileFolder======
on
deleteFileFolder(theParamList) --all worker processed scripts need "doScript" as handler.
   try -->>main library block --general fault protection
       
        
set errMsgText to "" --this can be used for non-terminal errors to return back to the script, if needed
       
        
try -->>required block  --verify that required parameters are available
           set rpTarget to (rpTarget of theParamList)
       on error errMsg --required block
           --terminal error, exit and return error
           return "Error: library_Template:deleteFileFolder(theParamList) required parameter missing - " & errMsg
       end try --required block
       try -->>set optional parameters
           set opContentsOnly to (opContentsOnly of theParamList)
       on error
           set opContentsOnly to false --set to default value if necessary
       end try
       
        
        
-->>
       if opContentsOnly = true or opContentsOnly = "true" then
           set targetList to {}
           repeat with aTarget in rpTarget
               set theTargetContents to (list folder aTarget)
               repeat with aTargetContent in theTargetContents
                   set posixTarget to (quoted form of (POSIX path of (aTarget & aTargetContent)))
                   copy posixTarget to end of targetList
               end repeat
           end repeat
           set AppleScript's text item delimiters to " "
           set targetList to (targetList as string)
           if targetList is not equal to "" then
               set theShellScript to "rm -r " & targetList
               do shell script theShellScript
           end if
       else
           set targetList to {}
           repeat with aTarget in rpTarget
               set posixTarget to (quoted form of (POSIX path of aTarget))
               copy posixTarget to end of targetList
           end repeat
           set AppleScript's text item delimiters to " "
           set targetList to (targetList as string)
           set theShellScript to "rm -r " & targetList
           do shell script theShellScript
       end if
       --<<--
       
        
    
on error errMsg --main library block
       set errMsgText to (errMsgText & errMsg & ">> Problem running library." & return)
   end try --main library block
   
    
set AppleScript's text item delimiters to ""
   if errMsgText ≠ "" then
       return errMsgText
   else
       return 0 --if it makes it this far, then all is well (I hope!)
   end if
end
deleteFileFolder



--========Libary  WriteToFile======
on
writeToFile(theParamList)
   try -->>main library block --general fault protection
       
        
set errMsgText to "" --this can be used for non-terminal errors to return back to the script, if needed
       set theDateString to "" --used for containing results from a shell script
       
        
try -->>required block  --verify that required parameters are available
           rpText of theParamList
           rpDest of theParamList
           rpFileName of theParamList
       on error errMsg --required block
           return "Error: library_WriteToFile:writeToLogFile(theParamList) required parameter missing - " & errMsg
       end try --required block
       
        
try -->>set optional parameters
           set opTimeStamp to (opTimeStamp of theParamList)
       on error
           set opTimeStamp to "" --set to default value if necessary
       end try
       try
           set opAppend to (opAppend of theParamList)
       on error
           set opAppend to "a" --set to default value if necessary
       end try
       
        
try -->> format date block
           if opTimeStamp ≠ "" then --add date stamp?
               if opTimeStamp contains "f" then --f (full overrides other formats)
                   set dateCommand to "date" --full date
               else
                   set dateCommand to "date +"
                   repeat with aTimeOption in opTimeStamp of theParamList
                       if aTimeOption as string = "t" then
                           set dateCommand to dateCommand & "_%H:%M:%S_" --wrap time into one format command
                       else
                           set dateCommand to dateCommand & "%" & aTimeOption & "/" --pass parameters into format command
                       end if
                   end repeat
               end if
               if dateCommand ≠ "" then
                   set theDateString to (do shell script dateCommand) & tab --shell command is easier to format than applescript
               end if
           end if
       on error errMsg -- format date block
           --terminal error, exit and return error
           return "Error: library_WriteToFile: problem formatting datestamp - " & errMsg
       end try -- format date block
       
        
set theFile to ((rpDest of theParamList) & (rpFileName of theParamList))
       
        
try -->>write block
           try
               close access file theFile --in case it was open
           end try
           open for access file theFile with write permission -- open the file to write
           if opAppend = "r" then
               set eof of file theFile to 0 --empty all data
           end if
           write (theDateString & (rpText of theParamList) as text) to file theFile starting at eof --write the data to the file
           close access file theFile --close the file
       on error errMsg --write block
           --terminal error, exit and return error
           try
               close access file theFile --close the file
           end try
           return "Error: library_WriteToFile: problem writing the file - " & errMsg
       end try --write block
       
    
on error errMsg --main library block
       set errMsgText to (errMsgText & errMsg & ">> Problem running library." & return)
   end try --main library block
   
    
set AppleScript's text item delimiters to ""
   if errMsgText ≠ "" then
       return errMsgText
   else
       return 0 --if it makes it this far, then all is well (I hope!)
   end if
end
writeToFile

_____________________________________________________________________________
Scanned by IBM Email Security Management Services powered by MessageLabs. For more information please visit http://www.ers.ibm.com
_____________________________________________________________________________
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Duplicate instead of Delete files in the list
      • From: LuKreme <email@hidden>
  • Prev by Date: Reveal / Select in Finder
  • Next by Date: Re: Duplicate instead of Delete files in the list
  • Previous by thread: Reveal / Select in Finder
  • Next by thread: Re: Duplicate instead of Delete files in the list
  • Index(es):
    • Date
    • Thread