Re: File name search & replace question
Re: File name search & replace question
- Subject: Re: File name search & replace question
- From: "Rips Ethan J" <email@hidden>
- Date: Tue, 29 Oct 2002 09:14:45 -0500
- Thread-topic: File name search & replace question
On Thursday, October 24, 2002, Emmanuel wrote:
>
The "Enhanced Find Dialog" provides Regular Expressions, which are able
>
to make sophisticated text changes as you need to. A menu lets you
>
choose to apply any given change either to a text window (so that you
>
can test, say if you've first copied a sample of file names into the
>
window) or to the names of the files you've first selected in Finder.
>
>
You could change "385SOI1.txt" into "SOI3851.txt" so that the
>
alphabetical order will sort the files by type. (I'm not sure I
>
understood everything about the "1", "2" which are appended sometimes).
>
>
About counting, you may also want to use the "Count" feature of that
>
same dialog.
>
>
If this can help, I made your list:
>
>
{"385SOI1.txt", "385SOI2.txt", "385SOA.txt", "385SOCR.txt",
>
"385SOAL.txt", "385SOO.txt", "385SOC1.txt", "385SOC2.txt",
>
"385CFIA.txt", "385CFIB.txt", "385CFIC.txt", "385CFIR.txt",
>
"385CFIT.txt"}
>
>
into:
>
>
{"SOI3851.txt", "SOI3852.txt", "SOA385.txt", "SOCR385.txt",
>
"SOAL385.txt", "SOO385.txt", "SOC3851.txt", "SOC3852.txt",
>
"CFIA385.txt", "CFIB385.txt", "CFIC385.txt", "CFIR385.txt",
>
"CFIT385.txt"}
>
>
by changing:
>
>
([0-9]{3})([A-Z]{3,4})([0-9]?)
>
>
into:
>
>
\2\1\3
Emmanuel-
I apologize for not explaining my dilemma with anywhere near enough clarity.
Here's the situation:
1. The file names to be sorted come from a folder selected by the user. The
Finder lists them in alphabetical order, which is not the correct order, like
so:
084Board members.txt
084cfi.txt
084NOTES.txt
084OFFICERS.txt
084opin.txt
084soal.txt
084soc.txt
084soff.txt
084soi.txt
084soo.txt
2. Reversing the alpha & numeric components of each filename via regular
expressions, as you've done above (plus a few minor tweaks), yields the
following:
Board members084.txt
cfi084.txt
NOTE084S.txt
OFFICERS084.txt
opin084.txt
soal084.txt
soc084.txt
soff084.txt
soi084.txt
soo084.txt
3. What I'm trying to figure out is how to match & rename patterns such that
the end result will be something like this:
001soi084.txt
002soi084.txt
003soff084.txt
004soal084.txt
005soo084.txt
006soc084.txt
007soc084.txt
008cfi084.txt
009cfi084.txt
010cfi084.txt
011cfi084.txt
012NOTE084S.txt
013opin084.txt
014OFFICERS084.txt
015Board members084.txt
In other words, the alpha portion of the code determines the order in which
the files are to be listed, but that order is not to be alphabetical. This
implies to me some sort of value pairing, such that "SOI" gets a prefix of
"001", "SOAL" gets "002", and so on.
4. Additionally, there are more such alpha code types:
SOI
SOA
SOCR
SOSS
SOFF
SOAL
SOO
SOC
CFI
NOTES
OPINION
TAX
OFFICERS
BOARD
SOCF
DIV
SELECTED INFO
PROXY
LPs
TOC
and there may be multiples of several of those types (SOIs, SOA, SOCR, SOSS,
SOFF, SOAL, SOO, SOC, CFI, NOTES)-hence the "1", "2", etc. that are appended
sometimes to the filenames.
5. There can be anywhere from 1 to 13 of each of these latter types (at latest
count) in a document, although the vast majority have between 1 and 4 SOI
files & only one of several of the others.
6. Every document has at least one of the following: SOI, SOAL, SOO, SOC, CFI,
NOTES.
So it seems to me that I've got to organize the searches something like this
(pseudo code):
search string for filenameTypeAlphaSegment (i.e., SOI, SOAL, SOO, SOC, CFI,
NOTES) (in loop)
--not sure how to do this. I know RegExp, but while I've finally learned how
to manipulate filename strings (a bit), I'm not sure how to structure searches
for a specific segment of a filename. In other words, I can access elements of
a string by position, but I don't know how to match a specific alpha pattern
in a string to an alpha search pattern.
set someList to (list of files in folder "blahblah" whose names include "SOI")
--This would have to be another sort, maybe requiring the files to be moved to
a specific location by type, I don't know...
--series of searches by file name type
--this is very rough--just an idea of the searches I'll have to write
set x to (count of items in soiList)
if item i of soiList contains "SOI" then
--I'll need another variable here containing the string
repeat with i in someList
set i to (i & filePrefix & "00" & i)
end repeat
end if
if item i of someList contains "SOA" then
repeat with i in someList
set i to (i & filePrefix & "00" & i)
end repeat
end if
if item i of someList contains "SOCR" then
repeat with i in someList
set i to (i & filePrefix & "00" & i)
end repeat
end if
if item i of someList contains "SOAL" then
repeat with i in someList
set i to (i & filePrefix & "00" & i)
end repeat
end if
if item i of someList contains "SOO" then
repeat with i in someList
set i to (i & filePrefix & "00" & i)
end repeat
end if
etc. as per the order in #4 above.
The result should be a list of files in the specific order of their appearance
in the document, which will enable my text cleanup script to insert them
programmatically into a BBEdit page, do the cleanup & insert the end result
into a Quark file. (The text cleanup script already works.)
Obviously, I'll want to modularize the whole mess via handlers, but first I
need to figure out a process that performs the steps outlined above.
Am I misconceiving what I've got to do? Do I have too many/too few steps? Are
there better ways to obtain the results I need?
Thank you very much for your feedback.
Ethan
_______________________________________________
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.