p01 Kansas City Southern
Skip to main content

Recent Topics

xx

xx

xx
new press - CIP3 files?
by johnny_jay
April 19, 2018, 03:42:45 PM

xx
Best free PDF Editor?
by Joe
April 18, 2018, 09:47:07 AM

xx
Epson 7900 - Out of register?
by ninjaPB_43
April 17, 2018, 06:27:55 PM

xx
Individual Page Proofs
by Tracy
April 17, 2018, 10:40:11 AM

xx

xx

Topic: AppleScript/Automator to create folder based on partial file name, move files (Read 4719 times) previous topic - next topic

Re: AppleScript/Automator to create folder based on partial file name, move files

Reply #15
Hi Joe,

The only thing it will accomplish if you don't have the files moved into new folder is to create a folder with the first 5 letters of the file name and stop. Is that all you are after?

This is exactly what I want to achieve. I will modify the existing files and then save them into the folder that was created by the script. I do not want the originals to be copied into the folders. I removed the last line and am keeping the original files

I am hoping this is just can be achieved by modifying a line in the script. I have played with it to get this result but unfortunately all I achieve is breaking the whole process!

Thanks in advance

Re: AppleScript/Automator to create folder based on partial file name, move files

Reply #16
OK, I'll try modifying it so it only creates a folder based upon the first 5 characters of the files in the folder. I assume if there is 24 files that start with 12345 you only want one folder named 12345, correct?
Mac OS 10.12 Sierra | Prinergy 7.5 | Adobe Creative Cloud 2017 | Two Luscher XPose 160 CTP units

Prepress: One who does precision guess work based on unreliable data provided by those of questionable knowledge.

Re: AppleScript/Automator to create folder based on partial file name, move files

Reply #17
Thats correct.

Right now it is perfect apart from it copies the original files into the created folders.

Again, thank you very much for your assistance.

Josh

Re: AppleScript/Automator to create folder based on partial file name, move files

Reply #18
OK I think this should work for you:

Code: [Select]
set chosenFolder to (choose folder)
tell application "Finder" to set fileList to files of chosenFolder

repeat with aFile in fileList
set {name:Nm, name extension:Ex} to info for (aFile as alias)
if Ex is missing value then set Ex to ""
if Ex is not "" then set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm
set dateFolder to text 1 thru 5 of Nm
set destinationFolder to quoted form of (POSIX path of chosenFolder & dateFolder)
do shell script "mkdir -p " & destinationFolder
end repeat
Mac OS 10.12 Sierra | Prinergy 7.5 | Adobe Creative Cloud 2017 | Two Luscher XPose 160 CTP units

Prepress: One who does precision guess work based on unreliable data provided by those of questionable knowledge.

Re: AppleScript/Automator to create folder based on partial file name, move files

Reply #19
Hi Joe,

Excellent script sir. Worked a treat.

Thanks very much

 

Re: AppleScript/Automator to create folder based on partial file name, move files

Reply #20
I've done enough Google research to know that this is possible, but haven't found anything that specifically does what I want it to do, and I'm not savvy enough to modify the existing scripts that I'm finding. If there are any AppleScript and/or Automator folks here that can help, here's what I want to accomplish:

I want to easily archive my 1-bit TIFFs into new folders, where the new folder is named the job number, which happens to be the first 5 characters of the 1-bit file names. So, if I have 20 files that are named like this:

32300_EdR_Sig_1A_K.tif
32300_EdR_Sig_1B_K.tif
32300_EdR_Sig_2A_K.tif
32300_EdR_Sig_2B_K.tif
and so on...

I want a folder to be created named "32300" and all the files that start with "32300" to be moved into that folder.

Any takers? I'm currently doing this manually and it sucks.

I know that this is an old topic, however another new topic pointed to this old post…

A cross platform alternative is to use ExifTool:

https://www.sno.phy.queensu.ca/~phil/exiftool/
https://www.sno.phy.queensu.ca/~phil/exiftool/#running
http://u88.n24.queensu.ca/exiftool/forum/index.php/topic,4888.0.html

The only real difference is that Windows OS uses straight double quotes to enclose strings of text such as file paths that contain word spaces (the Mac OS uses straight single quotes):

So to create a new folder on the Mac OS and move files into that folder, naming the folder after all of the leading characters up until the first underscore separator:

exiftool '-directory<${directory}/${filename;s#(^.+?)(_.+)#$1#}' -r 'pathTOtopLEVELfolder'

This code uses a regular expression capture group to isolate the required filename text to use for the folder name. This makes it quite easy to change the required folder name to suit different filename patterns.

Over and above the standard Mac Terminal CLI or Windows Command Prompt CLI or Windows PowerShell CLI – there are many other ways to run this code.

There are of course native methods on both platforms to script this task, without having to install 3rd party software such as ExifTool, this is just what works for me!