August 20, 2003
Making Things Easy; The Hard Way

As any of you that pay attention to my image archive know, I upload new pics to /image/new/incoming/yrmody. Where yrmody is the year,month,day the pictures were pulled off the camera. So today's would be 030820. And as long as I don't live until I'm 125 years old, that scheme should work just fine.

But I also have more meaningful directories. Dog pictures go to /images/pets/dogs/. So a time comes when the yrmody folder is a generation behind, and those pictures need moved to the myriad of /family and /friends and /events subdirs where they have a nicer contextual home.

So when that time comes, Kristi types up a list of which pics need to go where. And I move or copy them by hand. cp 117_1756* ../../../people/family/trevor Now when there are only 20 or so things to move, it's not a big deal. But I have over 200 pics in 080309. So it's far too much to do manually. And still have time to goof around.

Having spent a lot of time around a few code whores, I knew that there must be a way to script this. So I started thinking about it. Kristi already writes a list of files, I'd just need her to write that list in a given way.

Then my script would need to read the first line of that list and copy it to the destination I tell it. Then read in the second line, and copy it, and so on.

It sounds easy. And I'm sure it is. If you aren't a Code Moron. Like me.

So I google a bit. Don't find anything terribly useful. So I grab my Programming Perl 2nd Edition off the shelf. I wipe the dust off. And I turn to page 32.

And an hour later, I may be ready to start playing with some code. Being lazy has never been so much work.

Posted by danisaacs at August 20, 2003 10:34 PM | TrackBack
Comments

Heh.

This is how programming careers start. Luckily you're probably smart enough to steer clear of that.

Posted by: Jeremy Zawodny on August 21, 2003 03:10 AM

Amen. Morgan was signed on to YIM right before I went to bed. So I asked him about it. And a few minutes later he gave me usable code.

mv -vi --target-directory="$1" `cat "$2"`


Being a Code Mooch is so much easier than being a Code Whore.

Posted by: Code Mooch on August 21, 2003 06:26 AM

I can't even begin to tell you how many day-long projects came out of trying to avoid having to do 15 minutes worth of work....

Posted by: Mark on August 21, 2003 02:16 PM

Win32 Platform:
Populate file named list.txt with names you want to move. You can generate this list with a dir and pipe to text.
Create file Move.bat with the following:
copy %1 \\ Note:robocopy works nicely for this...
Create file called pics.bat with the following:
for /f %%1 in (list.txt) do move.bat %%1

Just take the time to modify source and target locations, and you should be good to go. Using AT or Scheduled Tasks you can have this run for you automatically once a week.

Posted by: WinAdmin on August 21, 2003 03:47 PM

Yes. I'm a Windows Admin myself. Unfortunatly, my batch and wsh skillz mean little to bash or perl. And my images are all on this server, which is Debian Linux.

The line in my previous post is what it takes in *nix, where $1 is a directory and $2 is a file that lists the files needed moved/copied. Replace mv with cp to copy.

The shell script I use to run the command is here:
http://danisaacs.com/scripts/move_files.sh.txt

Posted by: Arguably Dan on August 21, 2003 04:02 PM
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?