• 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
Re: Using list from text file to create folder, search, and copy
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using list from text file to create folder, search, and copy


  • Subject: Re: Using list from text file to create folder, search, and copy
  • From: Walter Ian Kaye <email@hidden>
  • Date: Mon, 2 Feb 2004 08:44:19 -0800

At 10:58a -0500 02/02/2004, Christopher Rosado didst inscribe upon an electronic papyrus:

Hi All,

I'm looking to automate the task of searching for specific files on my startup disk, create a new folder, then copy the files found to the new folder.

Ideally, I'd like to create a text document that would read:

Is this a document you will create manually, or do you want this to be automated as well? IOW, does it have to be human readable/writable?

--New Folder Name
group 1

--Files to search for and then copy
03432.jpg
593828.jpg
00435.jpg
info.txt
image1.tiff

There are many parts to creating this that I don't quite understand, starting with the idea of reading and then assigning variables from values contained in the aforementioned text document. There would be one folder per batch and there would not be a set # of files to be copied- that will vary.

There are many ways to delimit the data in the file. For example, the format you use in the example above would require the file to be read one line at a time and also for state to be maintained as you loop through the lines. You could also use an XML-ish format like so:
<folder>group 1</folder>
<files>03432.jpg
593828.jpg
00435.jpg
info.txt
image1.tiff</files>

Perhaps the simplest thing would be to just assume that the first line in the file is the folder name and all remaining lines are filenames (or pathnames, if they're coming from different locations, of course). Then you would just read the first line of the file, trim the trailing return, and assign it to your foldername variable; then read the rest of the file to build your list of filenames. Thus your file would look like this:

group 1
03432.jpg
593828.jpg
00435.jpg
info.txt
image1.tiff

Set up a file like that, and then run this script:

set datafile to "Disk:folder:folder:file" --wherever it is
set fref to open for access alias datafile
set folderName to read fref before return
read fref for 1 -- skip return
set fileList to every paragraph of (read fref)
close access fref

{folderName,fileList}

--you might end up with an empty item at the end if there was a blank line at the end of the file, so you might also want to check fileList for that and clean it up accordingly.


-Walter
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Using list from text file to create folder, search, and copy
      • From: email@hidden (Christopher Rosado)
References: 
 >Re: Shell-wrap a file in 2 variable strings (From: Gnarlodious <email@hidden>)
 >Re: Shell-wrap a file in 2 variable strings (From: Axel Luttgens <email@hidden>)
 >Using list from text file to create folder, search, and copy (From: email@hidden (Christopher Rosado))

  • Prev by Date: Using list from text file to create folder, search, and copy
  • Next by Date: Expect commands in Applescript
  • Previous by thread: Using list from text file to create folder, search, and copy
  • Next by thread: Re: Using list from text file to create folder, search, and copy
  • Index(es):
    • Date
    • Thread