|
|
|
|
#1 |
|
Prospect
Join Date: Jul 2007
Posts: 23
|
find files by number of charecters in file name
Hi all
i am trying to make an apple script that will go over a 3.5 Tera of hard disk find pdf files with names 11 characters long and copy the files to a selected location. sadly the find file in automator do not contain this Boolean. thanks for any help or ponters Last edited by ironchef; 12-29-2009 at 04:26 AM. |
|
|
|
|
|
#2 |
|
MVP
Join Date: Jan 2007
Posts: 1,751
|
You might experiment with find in Terminal. For targetfolder on the user's Desktop, I see that this command gets you part of the way to the goal:
find /Users/username/Desktop/targetfolder -name "*.pdf" (substitute your own username and the name of the targetfolder) Now the question is, for find, what can replace the * to specify exactly 11 wildcarded characters? (And do you really mean 11 characters, counting neither the pdf extension nor the . separator?) I can't work out the syntax, though it looks like the -regex option may be the key. |
|
|
|
|
|
#3 |
|
Hall of Famer
Join Date: Dec 2007
Posts: 3,642
|
I've never used it, but after reading this help request I happened to see a piece of software called LengthControl. It's free and looks like it may help with this task.
|
|
|
|
|
|
#4 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,941
|
The regex syntax for matching on number of characters in filenames with 'find' is discussed in this older thread: http://forums.macosxhints.com/showthread.php?t=97990
__________________
hayne.net/macosx.html |
|
|
|
|
|
#5 |
|
Prospect
Join Date: Jul 2007
Posts: 23
|
thanks to you all, ill try the find in terminal.
but, is there an apple script solution ? or is it "to deep" for applescript? |
|
|
|
|
|
#6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hall of Famer
Join Date: Apr 2002
Posts: 3,315
|
Does that "3.5 Tera of hard disk" include a Time Machine matrix by any chance? [i.e., any Backups.backupd database folders?] I think that -- unless provisions are made to record and skip duplicate inodes -- the copied result may contain multiple instances of each file. [i guess it also depends on the form of the copy command... perhaps redundancies will just overwrite previous copies, but that's still potentially wasteful (time + bandwidth) if these are large files.]
It could probably be done nicely in "pure" AppleScript... but would likely be longer than this: find -xE /path/to/source/folder -type f -iregex '.*/[^/]{11}\.pdf' [that's just the "find" part, but the "copying" part is also pretty short (using Bash).]
We still don't know yet. My command assumes 11 for name [not including ".pdf"] Hmm, "11" huh? Almost sounds like one of those "8+3 DOS" things, where we're looking for items that are 8 chars (or less) plus a 3 char extension which conform to that ancient requirement. (idunno) |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
#7 |
|
MVP
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
|
This is a snippet that I thought of, being a natural at the language:
[code] -- ……… set allFiles to {} -- files to copy repeat with i in the files set e to info for i set d to displayed name of e set c to kind of e if count characters of d is 11 then if c is "Portable Document Format (PDF)" then copy i to the end of allFiles end if end if end repeat duplicate allFiles to PATH_TO_LOC -- replace the PATH_TO_LOC with your path; you can also add 'with replacing' for elimination of duplicates. |
|
|
|
|
|
#8 |
|
MVP
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
|
Sorry, forget the end code fn.
Code:
-- ………
set allFiles to {} -- files to copy
repeat with i in the files
set e to info for i
set d to displayed name of e
set c to kind of e
if count characters of d is 11 then
if c is "Portable Document Format (PDF)" then
copy i to the end of allFiles
end if
end if
end repeat
duplicate allFiles to PATH_TO_LOC -- replace the PATH_TO_LOC with your path; you can also add 'with replacing' for elimination of duplicates.
|
|
|
|
|
|
#9 |
|
Prospect
Join Date: Jul 2007
Posts: 23
|
Thanks!
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|