Posts

Post not yet marked as solved
0 Replies
374 Views
Hello! I have thousands of files on an external drive that I would like to copy onto my Apple iMac drive. However, there are a lot of files that are not necessary. These files have a lot of extra characters at the end of the filename, which I have noted examples at the end as Excluded File End Strings. I would like to copy any files that do not have those strings at the end of the filename. Important: most of such excluded files do not have a file extension, they just appear in Finder as "Document". Next requirement: I would like to copy the folder structure from the source folder to the destination folder. If the folder doesn't exist in the destination then create it. For instance: source/test/2024, then create destination/test/2024 and put any files from that source sub folder in the destination subfolder. Last requirement: Create an output text file of all of the files actually copied over to the destination. Include the path, the filename, the file extension, the date, and the file size Create a summary count of files by file extension (eg jpg, xls, txt, etc) Create a grand total count of all files copied. Variables: Source file path: /Users/myfiles/Desktop/Cisco Destination file path: /Users/myfiles/Desktop/Destination Test Excluded File End Strings: /AFP_AfpInfo /com.apple.system.Security /com.apple.timemachine.private.directorycompletiondate /com.apple.quarantine /com.apple.macl /com.apple.lastuseddate#PS /com.apple.iwork.documentUUID#PS /com.apple.Preview.UIstate /com.intuit.turbotax /com.apple.metadata/_kMDItemUserTags /com.apple.metadata/kMDLabel I would prefer to see this in AppleScript, so that I can manage any other strings that need to be exlcluded. I have attached a screenshot of the source folder. Note that I only want to copy the 4 highlighted files of the 16 in this folder. The others should be excluded. I have also attached a script that I tried to write, but am getting the following error: error "Can’t get keys of {}." number -1728 from keys of {} Do you have any suggestions as to how I can accomplish this with AppleScript or an a better way? I do not understand what is causing the error. Thank you! Brian set sourceFolder to "/Users/blimbert/Desktop/Cisco" set destinationFolder to "/Users/blimbert/Desktop/Destination Test" -- List of filename patterns to exclude set excludedPatterns to {".AFP_AfpInfo", ".com.apple.system.Security", ".com.apple.timemachine.private.directorycompletiondate", ".com.apple.quarantine", ".com.apple.macl", ".com.apple.lastuseddate#PS", ".com.apple.iwork.document", ".com.apple.Preview.UIstate", ".com.intuit.turbotax", ".com.apple.metadata/_kMDItemUserTags", ".com.apple.metadata/kMDLabel"} -- Initialize file count by extension set fileCountByExtension to {} -- Get a list of files in the source folder using System Events tell application "System Events" set fileList to files of folder sourceFolder end tell -- Initialize variables to count copied files and store file listing set numFilesCopied to 0 set fileListing to "" -- Iterate through each file repeat with thisFile in fileList set fileName to name of thisFile set excludeFile to false -- Check if the file name matches any of the excluded patterns repeat with excludedPattern in excludedPatterns if fileName contains excludedPattern then set excludeFile to true exit repeat end if end repeat if not excludeFile then -- Get the file extension set fileExtension to text -4 thru -1 of fileName -- Get last four characters (extension) -- Update file count by extension if fileExtension is not in keys of fileCountByExtension then set fileCountByExtension's fileExtension to 1 else set fileCountByExtension's fileExtension to (fileCountByExtension's fileExtension) + 1 end if -- Increment the number of copied files set numFilesCopied to numFilesCopied + 1 end if end repeat -- Check if any files were processed if numFilesCopied = 0 then display dialog "No files were processed." else -- Generate summary by file extension set summaryText to "Summary by File Extension:" & linefeed repeat with fileExtension in keys of fileCountByExtension set countOfExtension to fileCountByExtension's fileExtension set summaryText to summaryText & " " & fileExtension & ": " & countOfExtension & linefeed end repeat -- Calculate grand total set grandTotal to sum of items of fileCountByExtension -- Append grand total to the summary set summaryText to summaryText & "Grand Total: " & grandTotal -- Display a dialog box with the summary display dialog "Total Files Copied: " & numFilesCopied & linefeed & summaryText buttons {"OK"} default button "OK" end if
Posted
by blimbert.
Last updated
.
Post not yet marked as solved
1 Replies
314 Views
Hello - I have a lot of photos and videos that end up in my downloads folder from amusement park photographers and rides. The problem is that when I go to download a recent trip the amusement park website downloads everything all over again, and creates a lot of folder and files in a random sequence. So I have to go through each folder and find the "new" files that I want to add to the Photos app. Could you please help me write a script that would search through the entire downloads folder, and copy all of the files that are of photo or video type, created on or after a specified date, into a new folder within the downloads folder? This is effectively just eliminating the subfolders that the website download process created. From there I would go to the newly created folder and sort by created date to obtain the new photos I want to add to the Photos app.
Posted
by blimbert.
Last updated
.