Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Use a unix-style syntax for copies names in Finder' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use a unix-style syntax for copies names in Finder
Authored by: duffster on Dec 07, '05 07:43:14AM

Any of you Unix junkies know how I can add a date to the file name?

For instance, when I duplicate a file, I want the original to be "document.txt" and the dupe to be "document_051207_bak.txt".



[ Reply to This | # ]
Use a unix-style syntax for copies names in Finder
Authored by: TrumpetPower! on Dec 07, '05 10:01:19AM

Your best bet would be to write a Perl program. Catching all the possibilities of extensions, no extensions, files with dots in their names and extensions...well, anybody who's got enough awk-fu to do it in the shell knows that Perl's a better fit.

Hmmm...you'd also have to take bundles into account. You can't rely on simple rules like ``period and up to four letters at the end is an extension'' because of things like ``.webarchive.'' All in all, unless you're doing a /lot/ of this kind of thing, your best bet is to rely on human rather than artificial intelligence.

If you're just wondering how to get the date into the filename, something like `date +%Y-%m-%d` (note the backticks) will expand out as you'd expect. See the man page for date for details.

Cheers,

b&



[ Reply to This | # ]
Use a unix-style syntax for copies names in Finder
Authored by: TrumpetPower! on Dec 07, '05 10:09:07AM

I should expand upon that reply just a bit more. The hint will only work with static text, best I know. To get the current date into the filename, you'd need some code to figure out what the current date is and how you'd like to format it. The hint will also apply to /every/ file you copy in the Finder.

If you do a lot of this sort of versioning thing, you're really better off with some sort of revision control system. And, OS X being Unix, it just happens that it ships with exactly that--good ol' RCS. Read the man page ``rcsintro'' to learn everything you need to know. But, in day-to-day use, it's no harder than ``ci -l filename'' when you want to check in a file with changes worth saving. You can then later check out any previous version, see comments for the various versions, compare differences between any two versions--all that good stuff.

Cheers,

b&



[ Reply to This | # ]
Use a unix-style syntax for copies names in Finder
Authored by: sjk on Dec 08, '05 02:41:33PM

If speed isn't critical, you could create an Automator workflow for Finder to do the style of file duplication you'd like. I've got a simple one called "Rename with YYYY-MM-DD" that renames selected files with their modification year-month-day appended.



[ Reply to This | # ]