Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 10-25-2003, 11:33 PM   #1
m0rph3us
Confirmed User
 
Join Date: Mar 2001
Location: Principality of Sealand
Posts: 2,033
attn: programmers - quick shell or perl script will paypal

I need a quick shell or perl script that renames files recursively.

I have 100k files all like this in multiple directories and subdirectories:

something_1.jpg something_10.jpg something_100.jpg
need to rename everything to
something_001.jpg something_010.jpg something_100.jpg

script should handle wildcards for the "something" as well as work recursively in directories (ie, I run it once, it seeks all *.jpg files as deep as possbile in the dir structure)

post your contact info icq me at 91603384. looking to get this done tonight or tomorrow. quick cash via paypal.

NB: This shell script has to run on FreeBSD or can be a perl script running in FreeBSD

cheers.
m0rph3us is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-26-2003, 12:32 AM   #2
m0rph3us
Confirmed User
 
Join Date: Mar 2001
Location: Principality of Sealand
Posts: 2,033
bump.
m0rph3us is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-26-2003, 12:42 AM   #3
goBigtime
Confirmed User
 
Join Date: Nov 2002
Posts: 7,761
hmm no I can't figure that one out quickly enough to be free, sorry

Last edited by goBigtime; 10-26-2003 at 12:46 AM..
goBigtime is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-26-2003, 12:47 AM   #4
Phil21
Confirmed User
 
Join Date: May 2001
Location: ICQ: 25285313
Posts: 993
Hehe..

One of my first ever times here someone asked for basically exactly this.

I did it, and then they didn't pay.

Ah.. memories.....

-Phil
__________________
Quality affordable hosting.
Phil21 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-26-2003, 12:47 AM   #5
goBigtime
Confirmed User
 
Join Date: Nov 2002
Posts: 7,761
it is ALWAYS

somethingunderscore#.jpg right?
goBigtime is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-26-2003, 01:26 AM   #6
Phil21
Confirmed User
 
Join Date: May 2001
Location: ICQ: 25285313
Posts: 993
Alright.. I got bored.

make a perl script somewhere on your server with the following in it:

#!/usr/bin/perl
# Renames stuff..
#

my $fn = $ARGV[0];
$fn =~ m/(.+[^\d])(\d+)\.(.+)/;
my $newfn = sprintf("%s%03d.%s",$1,$2,$3);

unless ($fn eq $newfn) {
`mv $fn $newfn`;
print "Moved $fn to $newfn\n";
} else {
print "skipped $fn\n";
}

then run something like:

find /home/phil21/gfyhelp -name \*.txt -exec /home/phil21/gfyhelp/rename.pl {} \;

(all on one line)

replace /home/phil21/gfyhelp w/ whatever directory you want to rename files in. change \*.txt to \*.jpg or whatever. If you have multiple extensions just run it multiple times, or make your own wildcard whatever. I just always, always have some form of control there out of habit. Saved my ass a few times.

and change /home/phil21/gfyhelp/rename.pl to the full path of wherever you put the perl script pasted above.

This will change any files to be 3 digits (1 to 001 21 to 021, 100 will stay the same, etc.), and output what it did. It works on any files that have digits before the dot, and at least one non-digit before those digits. (123something1.jpg would match, for example)

Shrug. works fine here. It's recursive and output is something like:

skipped /home/phil21/gfyhelp/foobar003.txt
Moved /home/phil21/gfyhelp/foobar3.txt to /home/phil21/gfyhelp/foobar003.txt
Moved /home/phil21/gfyhelp/recurs/foobar1.txt to /home/phil21/gfyhelp/recurs/foobar001.txt
Moved /home/phil21/gfyhelp/recurs/foobar3.txt to /home/phil21/gfyhelp/recurs/foobar003.txt
skipped /home/phil21/gfyhelp/foobar001.txt
skipped /home/phil21/gfyhelp/foobar002.txt
Moved /home/phil21/gfyhelp/foobar6.txt to /home/phil21/gfyhelp/foobar006.txt

will skip any files that source/dest are the same (if the digits don't need to be padded basically).

I would suggest copying your dir tree in full, and running this over that. Then once you look over to make sure it's correct putting on your live stuff.

-Phil
__________________
Quality affordable hosting.
Phil21 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-26-2003, 02:11 AM   #7
m0rph3us
Confirmed User
 
Join Date: Mar 2001
Location: Principality of Sealand
Posts: 2,033
hey phil thanks for the solution. works like a charm & best of all it's free. If you guys help your non-customers like this, I can't even imagine what you'd do if we were a customer

I'll definately check http://www.reflected.net for some deals soon.
m0rph3us is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-26-2003, 02:44 AM   #8
cheekycherry
Confirmed User
 
Join Date: Feb 2002
Location: N/A
Posts: 1,703
Quote:
Originally posted by m0rph3us
hey phil thanks for the solution. works like a charm & best of all it's free. If you guys help your non-customers like this, I can't even imagine what you'd do if we were a customer

I'll definately check http://www.reflected.net for some deals soon.
Pay the man... A good deed should always be rewarded. If you don't pay him, I will.
cheekycherry is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-26-2003, 02:47 AM   #9
JamesK
hi
 
Industry Role:
Join Date: Jun 2002
Posts: 16,731
sorry
__________________
M3Server - NATS Hosting
JamesK is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-26-2003, 03:19 AM   #10
TheViper
Confirmed User
 
Join Date: Mar 2003
Location: the streets.
Posts: 2,560
Quote:
Originally posted by Wildcard
sorry
LOL
TheViper is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-26-2003, 03:22 AM   #11
m0rph3us
Confirmed User
 
Join Date: Mar 2001
Location: Principality of Sealand
Posts: 2,033
Quote:
Originally posted by cheekycherry


Pay the man... A good deed should always be rewarded. If you don't pay him, I will.
I offered by phil refused payment. very kind of him
m0rph3us is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.