Copy a static file into matched folder?

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Copy a static file into matched folder? Wed Aug 22, 2012 8:18 pm • by eiff
Is there a way to do this? I was playing around with shell:

cp -f "/Users/david/Dropbox/bin/templates/hi.txt $1

but $1 isn't a directory (of course).

Thanks,
- David
eiff
 
Posts: 7
Joined: Mon Aug 20, 2012 8:14 pm

Re: Copy a static file into matched folder? Thu Aug 23, 2012 12:31 pm • by a_freyer
eiff wrote: ... but $1 isn't a directory (of course) ...


This confuses me - $1 would be the directory if you match the directory in your rule conditions. All you'd have to do is to add the filename to the $1:

Code: Select all
cp -f "/Users/andrewfreyer/hi.txt" "$1/Hi.txt"


Of course, you are going to have to set a flag to make sure that this doesn't copy indefinitely. I'd suggest a simple shell script checking if the file exists within the directory already - a simple "passes shell script" rule.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Copy a static file into matched folder? Thu Aug 23, 2012 3:04 pm • by Mr_Noodle
I guess you may want to back up a bit and explain what you are trying to do. As a_freyer noted, $1 will be the file or folder that is matched. If you are trying to match folders, then this would make sense but if you are matching a file, then I guess you might be trying to copy a file into the same folder as that file? If that is the case, then you need to extract the parent folder and copy to that using something like 'dirname'. Note if you do it this way, the file will get copied for every file in the folder that matches the rule.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Copy a static file into matched folder? Thu Aug 23, 2012 6:13 pm • by eiff
Thanks for the replies.

What I'm wanting is this:
I make a new folder for a new project.
When this happens the contents of another folder (my 'template' folder) copies into my newly created folder.

In other words: I need a basic set of files (a keynote presentation and a text file) for every project I do. When I create a folder for my new project, I want that basic set of files (the keynote template and the text file) to appear in my new project folder.

I think I got it.:

Code: Select all
If kind is folder
&
Date created is in the last 1 week

Run shell script: cp -f /Users/david/Dropbox/Speaking\ Outlines/bin/templates/* "$1"

Seems to be working, although a_freyer is right: This would run over and over. Especially since I rename the keynote file and text file to match the enclosing folder (the project) name once they appear.

Should I do a
Code: Select all
If 'date added' is newer than 'date last matched'

condition or something?
eiff
 
Posts: 7
Joined: Mon Aug 20, 2012 8:14 pm

Re: Copy a static file into matched folder? Thu Aug 23, 2012 6:22 pm • by a_freyer
I'd add a spotlight comment to the folder saying something like "Template Applied" and then filter your action excluding those:

Code: Select all
If (all) of the following conditions are met for (the file or folder being matched)
     Kind is folder
     Comments do not contain "Template Applied"

Do the following to the matched file or folder:
     Run shell script (embedded script)
     Add comment "Template Applied"
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Copy a static file into matched folder? Thu Aug 23, 2012 7:21 pm • by eiff
You guys are like the ninjas of the internet. Works perfectly.

Thanks so much for your time, seriously. :)
eiff
 
Posts: 7
Joined: Mon Aug 20, 2012 8:14 pm


Return to Support