Read records from a sequential file

I do have a file called “C5258.TXT”.

The file could contains multiple records which correspond to the name of specific pictures. I need to create a script which would open the file, read all records one by one and copy those pictures/files onto an external drive called NIKON01.

“C5258.TXT” is stored on my desktop and contains the following four records.

The first record of the file is the name of the person who wants to have the pictures to be copied onto NIKON1. The next three records are the actual picture I need to copy. All the pictures are located in a folder name “MyPictures”

Mary Nightingale
DSC_0177
DSC_0322
DSC_4501

The script would open the file “C5258.TXT”. Display in a dialog box the name of the person, followed by the name of the three files which will be copied. From the dialog box I will have to answer Yes or No for the Copy operation to occur.

I’ve been reading on the forum about AppleScript read statement. Unfortunately I do not where to start.

Can someone help me and show me how to read all record of a specific file?

Regards!
Daniel

Hi,

what does record mean? Is it an AppleScript record or just a couple of paragraphs?
In the latter case is there a way to distinguish real name and file name?

Hello Stefank,

In this case records mean rows.

Yes, I’ve made a change where the filename now correspond to something like an invoice number.

So you have a text file in which “records” are actually paragraphs?

Thanks Adam and StefanK,

I am starting to get there. I’ve wrote this little script which open the file I want to manipulate. It give me the right number of records (paragraphs in AppleScript).

However, I have an error when I try to display the content of a record.

Thanks!
Daniel

set theFile to choose file
set the_text to read theFile
set parcount to count paragraphs in the_text
display dialog parcount
repeat with x from 1 to parcount
	set nextpar to paragraph x of the_text
	display dialog x & " " & nextpar
end repeat

Display dialog boxes can only display text. Parcount is a number so it can’t display it. Also in your repeat loop you’re adding strings (eg. " " & nextpar) to a number. You can’t do that. However, you can coerce the number to text and then display that or add text to it. In addition, in your loop you get “paragraphs” every time. There’s overhead every time you do that so why not get “paragraphs” once? It’s just like you wouldn’t “read” the file multiple times. You do things once and then use those results multiple times. Try this…

set theFile to choose file
set the_text to read theFile
set the_list to paragraphs of the_text
set parcount to count of the_list
display dialog (parcount as text)
repeat with x from 1 to parcount
	set nextpar to item x of the_list
	display dialog (x as text) & " " & nextpar
end repeat

EXCELLENT - THANK YOU ALL for your help!

Daniel