New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Operating System General OS operation information and support

Seeking Applescript pro for a file search operation


Post Reply New Thread Subscribe

 
Thread Tools
Feee99

 
Member Since: Oct 13, 2011
Posts: 15
Feee99 is on a distinguished road

Feee99 is offline
Are you good with Applescript? If so I could definitely use your help.

All over my Mac's hard drive I have several files that begin with a 5 digit number in many different folders, i.e. "14452_car030.mov" and "12238_sidewalk060.mov"

Is there a way I can use Applescript to find every file that begins with file name "XXXXX" (where "XXXXX" is one of several hundred 5-digit numbers in a list- which I already have available). Then I would need it to move all those files to a specified folder. I wouldn't want it to copy and paste, but rather move, since I'm really just trying to wipe them off my Mac eventually.

The list of 5-digit numbers is over a thousand, and it's in .txt format (one per line). It looks something like this in notepad:

14452
12238
13345
15688
11920
etc.

And it would use this list to search for all files that start with "14452_etc." and all files that start with "12238_etc." and so forth. Your thoughts?
QUOTE Thanks
MacGrunt

 
MacGrunt's Avatar
 
Member Since: Aug 02, 2011
Posts: 17
MacGrunt is on a distinguished road

MacGrunt is offline
G'day Feee99

How far did you get with this? Are you still looking for help?

m.
QUOTE Thanks
Feee99

 
Member Since: Oct 13, 2011
Posts: 15
Feee99 is on a distinguished road

Feee99 is offline
Yes, I am still looking for help, if you happen to know a solution. Sorry for this late reply.
QUOTE Thanks
MacGrunt

 
MacGrunt's Avatar
 
Member Since: Aug 02, 2011
Posts: 17
MacGrunt is on a distinguished road

MacGrunt is offline
G'day

OK. I thought you were looking for help with an Applescript you were developing. It sounds like you are actually asking for a complete solution.

My apologies, I won't be able to work on this for the next few weeks but you'd probably be wanting to start with a spotlight search.
This will do a complete spotlight search of your machine and all associated volumes (but it will take a few minutes to run it) :
Code:
set mgFiles to get paragraphs of (do shell script "mdfind '(kMDItemFSName == \"*\")'")
If you know that all the files will be stored under a particular user then you'd restrict the search to speed things up (you need to change "macgrunt" to whatever your username is) :
Code:
set mgFiles to get paragraphs of (do shell script "mdfind  -onlyin /Users/macgrunt/ '(kMDItemFSName == \"*\")'")
If the files you are searching for are all .mov files then you'd add that to the filename to speed things up even more :
Code:
set mgFiles to get paragraphs of (do shell script "mdfind  -onlyin /Users/macgrunt/ '(kMDItemFSName == \"*.mov\")'")
Then you'd be wanting some repeat loops to compare your list of numbers with the results of the find. When it finds a match, you need to duplicate the found item to your new location before deleting the original item (ie. you can't 'move' files in the Finder with Applescript).

Sorry I can't help you more than that at this stage.
I'll get back to you with something more complete when I get a chance.

m.
QUOTE Thanks
Feee99

 
Member Since: Oct 13, 2011
Posts: 15
Feee99 is on a distinguished road

Feee99 is offline
Wow, this was a terrific help, thank you! It found all the .mov files on all three hard drives. They showed up in the Result field at the bottom of the Script Writer.

The ultimate goal is not to move the files, but to delete them. If we assume that deleting them within the Applescript is possible and would send them to the Trash, then I supposed I could glance through the Trash to double check the files when it's done.

The next step would be to have it look for the first five digits in all the .mov filenames, and comparing those digits to the list of 5 digit numbers in my .txt file. So, it would delete every .mov file which has its first 5 digits corresponding to any of the numbers in my .txt file.

My thinking is that I could drag the .txt file onto this Applescript, and it would run this process from there.

Thanks for following up. Even if this is something that would take a while, please let me know your thoughts on the feasibility of such an Applescript.
QUOTE Thanks
IvanLasston

 
IvanLasston's Avatar
 
Member Since: Feb 26, 2010
Location: Rocky Mountain High, Colorado
Posts: 2,116
IvanLasston is a splendid one to beholdIvanLasston is a splendid one to beholdIvanLasston is a splendid one to beholdIvanLasston is a splendid one to beholdIvanLasston is a splendid one to beholdIvanLasston is a splendid one to beholdIvanLasston is a splendid one to beholdIvanLasston is a splendid one to behold
Mac Specs: 1.8 GHz i7 MBA 11" OSX 10.8.2

IvanLasston is offline
You could also use terminal commands
Go to the highest level directory where all the movs are - in this example they are in my home directory under movies.
Code:
cd ~/Movies 
find . -name '[0-9][0-9][0-9][0-9][0-9]_*.mov' -print
The [0-9] is a regexp saying match a digit - you can change the range or set it to a specific digit - but there are 5 as you mentioned all movies have 5 digits and an _ (I think you mentioned the _) Anyway look here for more regular experssion magic.
http://www.regular-expressions.info/examples.html

This will show you all the files it finds. If this is to your liking then run the command with the -exec - you can either pass it to mv to move it to trash or rm to directly remove the file. Note - rm is final - there is no going back unless you use time machine so use these commands very very very carefully - especially with a recursive find.

To remove
Code:
find . -name '[0-9][0-9][0-9][0-9][0-9]_*.mov' -exec rm {} \;
To send to trash
Code:
find . -name '[0-9][0-9][0-9][0-9][0-9]_*.mov' -exec mv {} ~/.Trash \;
QUOTE Thanks
Feee99

 
Member Since: Oct 13, 2011
Posts: 15
Feee99 is on a distinguished road

Feee99 is offline
Would this be a drag and drop feature? Or, could I paste all the five digit numbers somewhere (as opposed to one at a time), and it would look for all of the files that start with those?

I wonder if there is software for searching for a long list of files... then I could just paste the 5-digit numbers into that... any ideas?
QUOTE Thanks

Post Reply New Thread Subscribe


« Security breach or back door in File Sharing? | Logic Studio Will Not Run! »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Can QT Pro Convert .mpg to an iMovie usable file? RageBiker Movies and Video 10 04-26-2009 12:03 PM
File maker pro jmanuel29 OS X - Apps and Games 0 07-01-2008 06:12 PM
My Tips for Search Engine Optimization iRock Web Design and Hosting 0 05-19-2007 10:34 PM
Windows 2003 File Server & Quark kegwell OS X - Operating System 0 01-15-2007 02:35 PM
OS9 File search W2003 petel Running Windows (or anything else) on your Mac 0 01-04-2006 08:09 AM

All times are GMT -4. The time now is 09:42 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?