Go Back   The macosxhints Forums > Working with OS X > OS X Developer



Reply
 
Thread Tools Rate Thread Display Modes
Old 12-29-2009, 03:55 AM   #1
ironchef
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.
ironchef is offline   Reply With Quote
Old 12-29-2009, 12:44 PM   #2
macosnoob
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.
macosnoob is offline   Reply With Quote
Old 12-29-2009, 01:48 PM   #3
NaOH
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.
NaOH is offline   Reply With Quote
Old 12-29-2009, 02:15 PM   #4
hayne
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
hayne is offline   Reply With Quote
Old 12-31-2009, 12:18 AM   #5
ironchef
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?
ironchef is offline   Reply With Quote
Old 12-31-2009, 01:37 PM   #6
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
Quote:
Originally Posted by ironchef
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.

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.]



Quote:
Originally Posted by ironchef
is there an apple script solution?
or is it "to deep" for applescript?

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).]



Quote:
Originally Posted by macosnoob
And do you really mean 11 characters, counting neither the pdf extension nor the . separator?

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)
Hal Itosis is offline   Reply With Quote
Old 01-11-2010, 06:43 AM   #7
renaultssoftware
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.
renaultssoftware is offline   Reply With Quote
Old 01-15-2010, 06:27 AM   #8
renaultssoftware
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.
renaultssoftware is offline   Reply With Quote
Old 02-09-2010, 02:59 AM   #9
ironchef
Prospect
 
Join Date: Jul 2007
Posts: 23
Thanks!
ironchef is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 01:26 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.