Cygwin is saving my ass

Morgan gangwere 0.fractalus@gmail.com
Tue Apr 1 01:52:00 GMT 2008


DePriest, Jason R. wrote:
> On Fri, Mar 28, 2008 at 12:04 PM, Morgan gangwere <> wrote:
>> Without cygwin, i wouldnt have my directory sorting algorithm running on
>>  windows. DOS has no way of (easily) sorting files into
>>  c:\{YEAR}\{MONTH}\{MIMETYPE}\
>>  (where Year Month and Mimetype are the year month and mimetype of the
>>  file in a list of oh say 30000 files.)
>>
>>  i _could_ impliment this in vb, but bash is faster.
>>  --
>>  Morgan Gangwere
>>
>>  Unknown Software
>>
> 
> Any chance you could share your bash script?  I have some perl scripts
> that are similar, but a pure bash script would be even better.
> 
> -Jason
> 

Its somwhere in my log... the basic idea is you have 2 shell scripts, 
one that does the move, another one that handles the list.
dotree.sh looks something like
--- start ---
# Get all files in cmd line:
for $f in $*
	echo "copy $f"
	fcopy $f >> stdout
rof
--- end --


and fcopy looks like
--- start ---
$fname = $1
#we can assume the file exists, as a glob was proabably used
# get the modify date and mimetype
$finfo={date =r=$fname +%Y_%j_%R}
$mime = {file -i $finfo}
$outname={basename $fname}
# now we copy the file
$TARGET = "\cygdrive\m\backups\$DATE"
echo "Copying $fname to $TARGET\$finfo\$mime\$outname" >> stdout
cp $fname "$TARGET\$finfo\$mime\$outname"
--- end ---

This will send the file "foo.txt" modified 3/14/15 at 06:06:06 to 
\cygdrive\m\backups\(todays date)\15_(day number for march 
14)_06:06:06\text/plain; charset=us-ascii\foo.txt"

Note that this can be a VERY useful system if you have a bunch of files 
and you can easily pick "foo.txt modified on blah", as this script will 
do it, and thats how my backup works. this MAY fail if you have multiple 
"foo.txt"s modified on the same day

note that is will fail as you cant cp files like that. but it is 
possible to use this as a base -- i am recalling this from memory.

--
Morgan Gangwere

Unknown Software

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list