New To Scripting

Hello everyone,

I am new to scripting. I know a few basics but not enough to do what i would like to do. I would like to know if this is possible with AS.
Any sample code to get me started would really help! Thanks in advance!!

I would like to write a script that will look at part of a file name then search for the folder which will be named to same. finally the script
moves the file in that correct folder.

Welcome to the bbs!

Yes that’s possible, but to help much some specifics are needed.

  1. How do we know what file name to look at? Is it selected?

  2. What is the generic structure of the name, i.e., what does a “typical” file name look like?

  3. Searching for a folder by name is easy, but are we looking for a name that matches the fragment from the file name or are we looking for a folder name that contains the fragment of the file name. Give us a sample.

Oh, and a word of advice – much faster answers result from meaningful titles for your posts. “New to Scripting” doesn’t attract a casual browser of the forum as quickly as “Match file names to folder names?”

Thank you for your reply.

The files will be in a folder somewhere in the finder. i havent yet decided on where. I would like to be able to select this folder
and the folder that i will be searched.

Here is the file stucture. The underlined part of the file name is the portion that is searched and matched to underline portion of the
Folder name. The naming scheme is very simple.

File Name: 2007.04.27 09.18.31_Room RM20A_Session 0830_09.10 Robert D. Fechtner.mp3
Folder Name: 20070427_RM20A_0830_09.10 Robert D. Fechtner

Sorry about the titling. i really wasn’t thinking about that. in the future i will have better titling. Thank you for your advice

Given the one sample of each and under the assumption that the files to be moved are all mp3, then

set folderWithFiles to (choose folder with prompt "Choose the folder containing the mp3 files")
set folderToSearchIn to (choose folder with prompt "Choose the folder holding the folders to move to")

-- Assuming the files to be found are all mp3 (if not say more)

tell application "Finder"
	set Fldr to folders of folderToSearchIn
	set F to files of folderWithFiles
	repeat with oneF in F
		set N to name of oneF --set N to name of oneF
		set tid to AppleScript's text item delimiters
		set AppleScript's text item delimiters to "Session "
		set TI to text item 2 of N
		set AppleScript's text item delimiters to ".mp3"
		set Session to text item 1 of TI
		set AppleScript's text item delimiters to tid
		repeat with aFldr in Fldr
			if Session is in name of aFldr then
				move oneF to aFldr
				exit repeat
			end if
		end repeat
	end repeat
end tell

Just in case the files are multiple extensions, running this on a string txt will return the text between the first "Session " and the last dot.

set txt to "2007.04.27 09.18.31_Room RM20A_Session 0830_09.10 Robert D. Fechtner.mp3"
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "Session "
set txt to text items 2 thru end of txt
set AppleScript's text item delimiters to astid
set txt to txt as text
set AppleScript's text item delimiters to "."
set txt to text items 1 thru -2 of txt
set AppleScript's text item delimiters to astid
return txt as text

You guys are amazing. Thank you so much!