moving unused of a website

moving unused of a website

am 15.04.2008 13:46:56 von mstep

Hello all,


I am a perl beginner. So patience please!


I wrote a perl-script to find all unused pix of a web site. Now I
would like to move all those 168! pix from the folder pix to the
folder pix_out keeping the same hierarchy as in the original folder.
That means:

/Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/thu mbnails/
tn_munich28.jpg

should be renamed to:

/Users/xxx/Documents/webpages/www.myproject.de/pix_out/fotos /
thumbnails/tn_munich28.jpg

Only one folder is changing his name: pix -> pix_out And this with all
my 168 unused pix in different folders.

I was hoping, that the rename function would create the missing
folders, doing:

rename "/Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/
thumbnails/tn_munich28.jpg", "/Users/xxx/Documents/webpages/
www.myproject.de/pix_out/fotos/thumbnails/tn_munich28.jpg";

But there is even no error message, trying to do it like this with one
test file. So probably I have to grep out the folders starting from
"pix"-folder until the file:

this would give in this example the folders fotos -> thumbnails which
are missing and which I have to create in pix_out - folder

My questions are:

How to grep these missing folders? Starting from pix, my hierarchy is
maximum 2 folders deep. But if there would be more folders?

how to test whether a folder is already created? I tried with:

if (-e ! $dir_pix_out)
#wrong!!
{
mkdir
$dir_pix_out;
}



thank you for your help



marek

Re: moving unused of a website

am 15.04.2008 15:57:20 von Peter Ludikovsky

Marek wrote:
>
> Hello all,
>
>
> I am a perl beginner. So patience please!
>
>
> I wrote a perl-script to find all unused pix of a web site. Now I
> would like to move all those 168! pix from the folder pix to the
> folder pix_out keeping the same hierarchy as in the original folder.
> That means:
>
> /Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/thu mbnails/
> tn_munich28.jpg
>
> should be renamed to:
>
> /Users/xxx/Documents/webpages/www.myproject.de/pix_out/fotos /
> thumbnails/tn_munich28.jpg
>
> Only one folder is changing his name: pix -> pix_out And this with all
> my 168 unused pix in different folders.
>
> I was hoping, that the rename function would create the missing
> folders, doing:
>
> rename "/Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/
> thumbnails/tn_munich28.jpg", "/Users/xxx/Documents/webpages/
> www.myproject.de/pix_out/fotos/thumbnails/tn_munich28.jpg";
>
> But there is even no error message, trying to do it like this with one
> test file. So probably I have to grep out the folders starting from
> "pix"-folder until the file:
>
> this would give in this example the folders fotos -> thumbnails which
> are missing and which I have to create in pix_out - folder
>
> My questions are:
>
> How to grep these missing folders? Starting from pix, my hierarchy is
> maximum 2 folders deep. But if there would be more folders?
>
> how to test whether a folder is already created? I tried with:
>
> if (-e ! $dir_pix_out)
> #wrong!!
> {
> mkdir
> $dir_pix_out;
> }
>
>
>
> thank you for your help
>
>
>
> marek

BEWARE, UNTESTED PSEUDOCODE
---SNIP---
use strict;
use warnings;

use File::Path;
use File::Basename;
use File::Copy;

my @moved=map{s/pix/pix_old/} @filelist;
for(my $i=0;$i<$#filelist;$i++){
mkpath(dirname($filelist[$i]));
move($filelist[$i],$moved[$i]);
}
---SNIP---

as said, that code is neither tested nor beautiful, but it should give
you an idea on how to start...

hth
/peter

Re: moving unused of a website

am 15.04.2008 16:18:38 von 1usa

Marek wrote in
news:3547d8bf-791e-4854-b2c8-
d50a557c8c0d@c19g2000prf.googlegroups.co
m:

> I am a perl beginner.

You are a Perl beginner. Perl is the language, perl is the binary.

perldoc -q difference

> So patience please!
>
>
> I wrote a perl-script to find all unused pix of a web site. Now I
> would like to move all those 168! pix from the folder pix to the
> folder pix_out keeping the same hierarchy as in the original
> folder. That means:
>
> /Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/
> thumbnails/tn_munich28.jpg
>
> should be renamed to:
>
> /Users/xxx/Documents/webpages/www.myproject.de/pix_out/fotos /
> thumbnails/tn_munich28.jpg

Learn to use the right tool for the job. The command line tool move
is perfect for this.

move /Users/xxx/Documents/webpages/www.myproject.de/pix
/Users/xxx/Documents/webpages/www.myproject.de/pix_out

> Only one folder is changing his name: pix -> pix_out And this with
> all my 168 unused pix in different folders.

I am not sure what you mean by this.


> I was hoping, that the rename function would create the missing
> folders, doing:
>
> rename "/Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/
> thumbnails/tn_munich28.jpg", "/Users/xxx/Documents/webpages/
> www.myproject.de/pix_out/fotos/thumbnails/tn_munich28.jpg";
>
> But there is even no error message, trying to do it like this with
> one test file.

Why would there be an error message if you don't ask for it?

#!/usr/bin/perl

use strict;
use warnings;

my ($old, $new) = ( 'does not exist', 'miracle' );

rename $old => $new
or die "Cannot rename '$old' to '$new': $!";

__END__

C:\Temp> t9
Cannot rename 'does not exist' to 'miracle': No such file or
directory at C:\Temp\t9.pl line 8.

> how to test whether a folder is already created? I tried with:
>
> if (-e ! $dir_pix_out)

WTF?

mkdir $dir unless -d $dir;

or

mkdir $dir unless ! -d $dir;

or

if ( ! -d $dir ) {

}

C:\Temp\t> cat t0.pl
#!/usr/bin/perl

use strict;
use warnings;

mkdir 's' unless -d 's';

mkdir 't' if ! -d 't';

if ( ! -d 'u' ) {
mkdir 'u';
}

unless ( -d 'v' ) {
mkdir 'v';
}

__END__

C:\Temp\t> t0

2008/04/15 10:14 AM

s
2008/04/15 10:14 AM t
2008/04/15 10:14 AM u
2008/04/15 10:14 AM v


However, testing and creation of the directory is not done in a
single atomic transaction. Therefore, testing the existence of the
directory before attempting to create it is of dubious use. Just do

mkdir $dir;

and make sure to check for errors in subsequent file operations
because a directory that existed a few statements back can disappear
once you reach the file operations.

Sinan

--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Re: moving unused of a website

am 15.04.2008 17:38:51 von mstep

Thank you Sinan and Peter for you prompt answers!


Meanwhile I made some progress myself. I am reading in the file name
of the unused pix, and then a grep starting with my "pix" folder, and
then splitting over '/'. The result is three array elements, and the
file name. I am testing, whether the two folders are existing, and if
not, create them. Is this a good approach? (My test script follows on
the bottom).

But I will think over your hints and try to integrate your advices!


marek


#! /usr/local/bin/perl

use strict;
use warnings;
use Data::Dumper;

my $start_dir = "/Users/xyz/Documents/webpages/www.myproject.de";

my $pix_unused_pix =
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/fotos /
thumbnails/tn_munich17.jpg"; # an example of an unused pix

my ($path) = $pix_unused_pix =~ m~/pix/([^"]+?)$~;

my @folders = split("/",$path);


print "The missing folders are:\n\n";
print Dumper(@folders);
print "\n\n";

chdir($start_dir);

if (-e $folders[1]) {
print "\nYes, your folder /$folders[1] exists!\n\n";
}

if (!-e $folders[1]) {
print "\nNO! Your folder /$folders[1] does not exists!\n\n";
mkdir $folders[1];
}

if (-e $folders[1].'/'.$folders[2]) {
print "\nYes, your folder /$folders[1]/$folders[2] exists!\n\n";
}

if (!-e $folders[1].'/'.$folders[2]) {
print "\nNO! Your folder /$folders[1]/$folders[2] does not exists!
\n\n";
mkdir $folders[1] . '/' . $folders[2];
}

Re: moving unused of a website

am 15.04.2008 18:31:17 von it_says_BALLS_on_your forehead

On Apr 15, 10:18=A0am, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:

> mkdir $dir unless -d $dir;
>
> or
>
> mkdir $dir unless ! -d $dir;
>

I think here, you meant:

mkdir $dir if ! -d $dir;

Re: moving unused of a website

am 15.04.2008 18:31:28 von jurgenex

Marek wrote:
>Meanwhile I made some progress myself. I am reading in the file name
>of the unused pix, and then a grep starting with my "pix" folder, and
>then splitting over '/'. The result is three array elements, and the
>file name.

You may want to look at File::Basename which has functions to split a
file path into its components.

>I am testing, whether the two folders are existing, and if
>not, create them. Is this a good approach? (My test script follows on
>the bottom).

You may want to look at File::Path which provides mkpath() to create
file paths of any depth.

>print Dumper(@folders);

Why not a simple
print @folders;

jue

Re: moving unused of a website

am 15.04.2008 19:39:50 von mstep

Thank you all! Yes I will look into all your suggestions. Meanwhile I
am progressing on my own way but I will seriously look into all your
suggestions tomorrow.


marek


*******I am here now! I will make a subroutine in my perl script out
of it. If you have any suggestions directly to this script ...

#! /usr/local/bin/perl

use strict;
use warnings;


my $start_dir = "/Users/xyz/Documents/webpages/www.myproject.de";
my $pix_out_folder = $start_dir . "/pix_out";
my $pix_unused_pix =
"/Users/xyz/Documents/webpages/www.myproject.de/pix/fotos/th umbnails/
tn_munich17.jpg";

my ($path) = $pix_unused_pix =~ m~/pix/([^"]+?)$~;

my @folders = split( "/", $path );

if ( !-e $pix_out_folder ) {
mkdir $pix_out_folder
or die "could not create your folder: $pix_out_folder! $!";
}

my $first_sub = shift @folders unless $folders[0] =~ m~\.(jpe?g|gif|
png)$~;
$first_sub = $pix_out_folder . '/' . $first_sub if $first_sub;

if ( $first_sub and !-e $first_sub ) {
print "\nNO! Your folder /$folders[1] does not exists!\n\n";
mkdir $first_sub or die "could not create your folder: \"$first_sub
\"! $!";
}

my $second_sub = shift @folders unless $folders[0] =~ m~\.(jpe?g|gif|
png)$~;
$second_sub = $first_sub . '/' . $second_sub if $second_sub;

if ( $second_sub and !-e $second_sub ) {
print "\nNO! Your folder $second_sub does not exists!\n\n";
mkdir $second_sub
or die "could not create your folder: \"$second_sub\"! $!";
}

my $third_sub = shift @folders unless $folders[0] =~ m~\.(jpe?g|gif|
png)$~;
$third_sub = $second_sub . '/' . $third_sub if $third_sub;

if ( $third_sub and !-e $third_sub ) {
print "\nNO! Your folder $third_sub does not exists!\n\n";
mkdir $third_sub or die "could not create your folder: \"$third_sub
\"! $!";
}

Re: moving unused of a website

am 15.04.2008 20:12:51 von someone

Peter Ludikovsky wrote:
> Marek wrote:
>>
>> I wrote a perl-script to find all unused pix of a web site. Now I
>> would like to move all those 168! pix from the folder pix to the
>> folder pix_out keeping the same hierarchy as in the original folder.
>> That means:
>>
>> /Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/thu mbnails/
>> tn_munich28.jpg
>>
>> should be renamed to:
>>
>> /Users/xxx/Documents/webpages/www.myproject.de/pix_out/fotos /
>> thumbnails/tn_munich28.jpg
>
> BEWARE, UNTESTED PSEUDOCODE
> ---SNIP---
> use strict;
> use warnings;
>
> use File::Path;
> use File::Basename;
> use File::Copy;
>
> my @moved=map{s/pix/pix_old/} @filelist;

Now @moved contains a list of either '1' or '' depending of whether
/pix/ matched or not. And all the elements of @filelist have been
modified so that 'pix' is replaced with 'pix_old'.


> for(my $i=0;$i<$#filelist;$i++){

You have an off-by-one error. You are iterating through the first
element of @filelist through the second-to-last element of @filelist.


> mkpath(dirname($filelist[$i]));
> move($filelist[$i],$moved[$i]);
> }
> ---SNIP---
>
> as said, that code is neither tested nor beautiful, but it should give
> you an idea on how to start...


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Re: moving unused of a website

am 15.04.2008 20:18:34 von Ben Morrow

Quoth Marek :
>
> I wrote a perl-script to find all unused pix of a web site. Now I
> would like to move all those 168! pix from the folder pix to the
> folder pix_out keeping the same hierarchy as in the original folder.

168! is approximately 10^302. I'm impressed you have a filesystem with
that many inodes...

> That means:
>
> /Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/thu mbnails/
> tn_munich28.jpg
>
> should be renamed to:
>
> /Users/xxx/Documents/webpages/www.myproject.de/pix_out/fotos /
> thumbnails/tn_munich28.jpg
>
> Only one folder is changing his name: pix -> pix_out And this with all
> my 168 unused pix in different folders.
>
> I was hoping, that the rename function would create the missing
> folders, doing:
>
> rename "/Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/
> thumbnails/tn_munich28.jpg", "/Users/xxx/Documents/webpages/
> www.myproject.de/pix_out/fotos/thumbnails/tn_munich28.jpg";

No, rename doesn't do that.

> But there is even no error message, trying to do it like this with one
> test file.

There is no error message because you didn't ask for one. Always check
the return value of system calls.

my $src = "/Users/...";
(my $dst = $src) =~ s,/pix/,/pix_out/,;

rename $src, $dst or die "can't rename $src -> $dst: $!";

> So probably I have to grep out the folders starting from "pix"-folder
> until the file: this would give in this example the folders fotos ->
> thumbnails which are missing and which I have to create in pix_out -
> folder

You can use File::Basename or File::Spec to find the directory you are
trying to rename into, and File::Path to create the whole directory tree
required in one step.

> how to test whether a folder is already created? I tried with:
>
> if (-e ! $dir_pix_out) #wrong!! { mkdir $dir_pix_out; }

Huh? What made you think that would work? Assuming $dir_pix_out contains
a filename, it is a true value. This means ! $die_pix_out is undef, and
you are trying to test for the existance of a file with an empty name.
You will also get a warning: do you have warnings switched on?

The test for a directory is -d, so you want

if (! -d $dir_pix_out) {

or

unless (-d $dor_pix_out) {

Note that mkdir doesn't create multiple levels of directory, either;
again, you need to use File::Path.

Ben

Re: moving unused of a website

am 16.04.2008 00:36:10 von benkasminbullock

On Tue, 15 Apr 2008 14:18:38 +0000, A. Sinan Unur wrote:

>> I wrote a perl-script to find all unused pix of a web site. Now I would
>> like to move all those 168! pix from the folder pix to the folder
>> pix_out keeping the same hierarchy as in the original folder. That
>> means:
>>
>> /Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/
>> thumbnails/tn_munich28.jpg
>>
>> should be renamed to:
>>
>> /Users/xxx/Documents/webpages/www.myproject.de/pix_out/fotos /
>> thumbnails/tn_munich28.jpg
>
> Learn to use the right tool for the job. The command line tool move is
> perfect for this.
>
> move /Users/xxx/Documents/webpages/www.myproject.de/pix
> /Users/xxx/Documents/webpages/www.myproject.de/pix_out

As far as I can understand the original poster has a list of pictures he
wants to move to directories with the name changed in the middle of the
list. What you're suggesting is going to move everything in the
directories, not just the pictures he wants to move.

>> Only one folder is changing his name: pix -> pix_out And this with all
>> my 168 unused pix in different folders.
>
> I am not sure what you mean by this.

Well, why post a reply to a question, if you don't understand it?

>
>> I was hoping, that the rename function would create the missing
>> folders, doing:
>>
>> rename "/Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/
>> thumbnails/tn_munich28.jpg", "/Users/xxx/Documents/webpages/
>> www.myproject.de/pix_out/fotos/thumbnails/tn_munich28.jpg";
>>
>> But there is even no error message, trying to do it like this with one
>> test file.
>
> Why would there be an error message if you don't ask for it?

Whether there's an error message depends on the detailed behaviour of the
function in question.

>> how to test whether a folder is already created? I tried with:
>>
>> if (-e ! $dir_pix_out)

Here you need to say

if (!-d $dir_pix_out)

> However, testing and creation of the directory is not done in a single
> atomic transaction. Therefore, testing the existence of the directory
> before attempting to create it is of dubious use.

Really?

> Just do
>
> mkdir $dir;
>
> and make sure to check for errors in subsequent file operations because
> a directory that existed a few statements back can disappear
> once you reach the file operations.

Really? I've never experienced that.

Re: moving unused of a website

am 16.04.2008 02:08:45 von 1usa

Ben Bullock wrote in
news:fu3akp$pl5$1@ml.accsnet.ne.jp:

> On Tue, 15 Apr 2008 14:18:38 +0000, A. Sinan Unur wrote:
>
>>> I wrote a perl-script to find all unused pix of a web site. Now
>>> I would like to move all those 168! pix from the folder pix to
>>> the folder pix_out keeping the same hierarchy as in the original
>>> folder. That means:
>>>
>>> /Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/
>>> thumbnails/tn_munich28.jpg
>>>
>>> should be renamed to:
>>>
>>> /Users/xxx/Documents/webpages/www.myproject.de/pix_out/fotos /
>>> thumbnails/tn_munich28.jpg
>>
>> Learn to use the right tool for the job. The command line tool
>> move is perfect for this.
>>
>> move /Users/xxx/Documents/webpages/www.myproject.de/pix
>> /Users/xxx/Documents/webpages/www.myproject.de/pix_out
>
> As far as I can understand the original poster has a list of
> pictures he wants to move to directories with the name changed in
> the middle of the list. What you're suggesting is going to move
> everything in the directories, not just the pictures he wants to
> move.

Well, I understood differently but your explanation makes more
sense.

>>> Only one folder is changing his name: pix -> pix_out And this
>>> with all my 168 unused pix in different folders.
>>
>> I am not sure what you mean by this.
>
> Well, why post a reply to a question, if you don't understand it?

So that the OP can clarify it if he feels like it.

>>> I was hoping, that the rename function would create the missing
>>> folders, doing:
>>>
>>> rename
>>> "/Users/xxx/Documents/webpages/www.myproject.de/pix/fotos/
>>> thumbnails/tn_munich28.jpg", "/Users/xxx/Documents/webpages/
>>> www.myproject.de/pix_out/fotos/thumbnails/tn_munich28.jpg";
>>>
>>> But there is even no error message, trying to do it like this
>>> with one test file.
>>
>> Why would there be an error message if you don't ask for it?
>
> Whether there's an error message depends on the detailed behaviour
> of the function in question.

The caller should check if the function returned an error and
display the error message if necessary. I also showed how to do
that.

>> However, testing and creation of the directory is not done in a
>> single atomic transaction. Therefore, testing the existence of
>> the directory before attempting to create it is of dubious use.
>
> Really?

IMHO, yes. If the directory already exists, nothing will happen. If
it does not it will created (assuming no permissions issues).

>> Just do
>>
>> mkdir $dir;
>>
>> and make sure to check for errors in subsequent file operations

This is the important part. Especially in a scenario which I have
seen occasionally in others' code where the existence of the target
directory is checked before a lengthy loop of file copy operations.

>> because a directory that existed a few statements back can
>> disappear once you reach the file operations.
>
> Really? I've never experienced that.

Ahem, I hate to admit it, but I am not sure exactly what I was
thinking of. I seem to remember such a caution but I am not sure
now.

Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Re: moving unused of a website

am 16.04.2008 03:47:20 von Tad J McClellan

John W. Krahn wrote:
> Peter Ludikovsky wrote:

>> for(my $i=0;$i<$#filelist;$i++){
>
> You have an off-by-one error. You are iterating through the first
> element of @filelist through the second-to-last element of @filelist.


If you had used the standard Perl idiom

foreach my $i ( 0 .. $#filelist ) {

instead of a C-style for(;;) loop, you would have had less
chance of inserting such a bug...

(and whitespace is not a scarce resource, so use some!)


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Re: moving unused of a website

am 16.04.2008 03:47:21 von Tad J McClellan

Marek wrote:

> my $pix_unused_pix =
> "/Users/xyz/Documents/webpages/www.myproject.de/pix/fotos/th umbnails/
> tn_munich17.jpg";

Look Ma! No wordwrap!

my $pix_unused_pix = '/Users/xyz/Documents/webpages/www.myproject.de/'
. 'pix/fotos/thumbnails/tn_munich17.jpg';


> if ( !-e $pix_out_folder ) {

unless ( -e $pix_out_folder ) {


> $first_sub = $pix_out_folder . '/' . $first_sub if $first_sub;

$first_sub = "$pix_out_folder/$first_sub" if $first_sub;


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Re: moving unused of a website

am 16.04.2008 16:09:58 von Lawrence Statton

Tad J McClellan writes:
>
> (and whitespace is not a scarce resource, so use some!)
>

You young'ns don't remember the great whitespace shortage of '03
.... all the new python people were using all the whitespace that could
be produced -- a lot of programmers had to go mining in old COBOL and
FORTRAN projects of their college days just to get enough whitespace
to keep our variables separated.

--
Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
place them into the correct order.

Re: moving unused of a website

am 16.04.2008 19:04:27 von mstep

Sorry to bother this group again! Now my script is nearly finished.
Only one little problem is left: I am imaging the perl "rename" like
the shell "mv". Is there a difference? My rename is not working as
intended:

could not rename your pix from:
/Users/marekstepanek/Documents/webpages/www.munich-taxis.de/
pix/fotos/thumbnails/tn_munich28.jpg
to
/Users/marekstepanek/Documents/webpages/www.munich-taxis.de/
pix_out/fotos/thumbnails/tn_munich28.jpg


Here the last version of my script.


Best greetings


marek


***************



#! /usr/local/bin/perl

use strict;
use warnings;


my $start_dir = "/Users/xyz/Documents/webpages/www.munich-taxis.de";
my $pix_out_folder = "$start_dir/pix_out";
my @unused_pix = (
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/fotos /
thumbnails/tn_munich28.jpg",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp1/
no_n.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp5/
hili_-09.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/
norm_upb.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/
hili_upb.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp5/
hili_-08.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/
norm_dn.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp2/
hili_subchap10.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp2/
hili_db.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp2/
norm_up.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp5/
hili_subchap07.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/
no_fr.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp5/
hili_-11.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp5/
acti_subchap10.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/
rahmen_unten01_10.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp4/
hili_subchap10.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp5/
acti_subchap08.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp5/
hili_up.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp5/
hili_subchap05.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp2/
hili_up.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/
hili_upn.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp2/
norm_tacho_ul_00.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/grafi x/chp4/
hili_up.gif",
"/Users/xyz/Documents/webpages/www.munich-taxis.de/pix/fotos /
munich04_03w.jpg"
);

unless ( -d $pix_out_folder ) {
mkdir $pix_out_folder
or die "could not create your folder: $pix_out_folder! $!\n\n";
}



foreach my $pix (@unused_pix) {
my ($path) = $pix =~ m~/pix/([^"]+?)$~;

my @folders = split( "/", $path );

# what happens if there is a deeper hierarchy? So we have to
iterate over
# all elements of @folders

foreach my $sub (@folders)
{
last if $folders[0] =~ m~\.(jpe?g|gif|png)$~;
$sub = shift @folders;
$sub = "$pix_out_folder/$sub";

if ( $sub and !-d $sub ) {
print "\nNO! Your folder \"$sub\" does not exists!\n\n";
mkdir $sub
or die "could }
}
}

foreach my $pix (@unused_pix)
{
my $old = $pix;
$pix =~ s~/pix/~/pix_out/~;
my $new = $pix;
rename $old, $new or die "could not rename your pix from:\n\t$old
\nto\n\t$new\n\n $!";
}

Re: moving unused of a website

am 16.04.2008 19:10:19 von jurgenex

Marek wrote:
>Only one little problem is left: I am imaging the perl "rename" like
>the shell "mv". Is there a difference? My rename is not working as
>intended:

Did you read the documentation for rename()? I think it is very clear.

>could not rename your pix from:
> /Users/marekstepanek/Documents/webpages/www.munich-taxis.de/
>pix/fotos/thumbnails/tn_munich28.jpg
>to
> /Users/marekstepanek/Documents/webpages/www.munich-taxis.de/
>pix_out/fotos/thumbnails/tn_munich28.jpg

You might want to include the reason _why_ the rename failed. That will
probably give you some hint as to how to fix it.

jue

Re: moving unused of a website

am 16.04.2008 20:29:01 von Ted Zlatanov

Lawrence Statton wrote:
> You young'ns don't remember the great whitespace shortage of '03
> ... all the new python people were using all the whitespace that could
> be produced -- a lot of programmers had to go mining in old COBOL and
> FORTRAN projects of their college days just to get enough whitespace
> to keep our variables separated.

Perl, fortunately, was not affected by this shortage by design :)

Ted

Re: moving unused of a website

am 16.04.2008 22:34:05 von it_says_BALLS_on_your forehead

On Apr 16, 1:04=A0pm, Marek wrote:
> Sorry to bother this group again! Now my script is nearly finished.
> Only one little problem is left: I am imaging the perl "rename" like
> the shell "mv". Is there a difference? My rename is not working as
> intended:
>
> could not rename your pix from:
> =A0 =A0 =A0 =A0 /Users/marekstepanek/Documents/webpages/www.munich-taxis.d=
e/
> pix/fotos/thumbnails/tn_munich28.jpg
> to
> =A0 =A0 =A0 =A0 /Users/marekstepanek/Documents/webpages/www.munich-taxis.d=
e/
> pix_out/fotos/thumbnails/tn_munich28.jpg
>

check out File::Copy::move()

Re: moving unused of a website

am 20.04.2008 10:50:17 von rvtol+news

Ted Zlatanov schreef:
> Lawrence Statton wrote:

>> You young'ns don't remember the great whitespace shortage of '03
>> ... all the new python people were using all the whitespace that
>> could be produced -- a lot of programmers had to go mining in old
>> COBOL and FORTRAN projects of their college days just to get enough
>> whitespace to keep our variables separated.
>
> Perl, fortunately, was not affected by this shortage by design :)

Per 6 is too modern for that:
"Whitespace is in general required between any keyword and any opening
bracket that is not introducing a subscript or function arguments. Any
keyword followed directly by parentheses will be taken as a function
call instead."

sub if { exit 1 }

--
Affijn, Ruud

"Gewoon is een tijger."