Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: file case change

by costas (Scribe)
on Mar 15, 2002 at 12:22 UTC ( [id://151965]=note: print w/replies, xml ) Need Help??


in reply to file case change

I cant seem to get this working. I have been trying for ages but with no succes. the results are printed below
#!/usr/bin/perl -w BEGIN { $|=1; print "Content-type: text/html\n\n"; use CGI::Carp('fatalsToBrowser'); } use strict; my $file; my $path = '/home/costas/test'; opendir (DIR, $path) or die "Can't opendir: $!"; for (readdir DIR) { print "$_<br>"; rename("$path/$_", lc("$path/$_")) or print "Couldn't rename $file +: $!\n"; } closedir DIR;
Couldn't rename : Not a directory .. Couldn't rename : Device or resource busy safdLLP.txT.txt Couldn't rename : Permission denied safdLLPt.txT.txt Couldn't rename : Permission denied
can anybody see why this is happening? I tried to add the path and it still doesnt work?

Replies are listed 'Best First'.
Re: Re: file case change
by ChOas (Curate) on Mar 15, 2002 at 12:26 UTC
    Okay:
    change
    for (readdir DIR) { print "$_<br>"; rename("$path/$_", lc("$path/$_")) or print "Couldn't rename $file +: $!\n"; }
    to:
    for (readdir DIR) { next if (/^\.{1,2}$/); print "$_<br>"; rename("$path/$_", lc("$path/$_")) or print "Couldn't rename $_: $ +!\n"; }

    GreetZ!,
      ChOas

    print "profeth still\n" if /bird|devil/;

      This is really bad code. First you lowercase the whole file path ensuring that any uppercase path will break this code (as when you lowercase it you will then try to write along a non existant path). Next you seem to have forgotten that '.' and '..' are not the only directories you might find. Finally you should never print unescaped arbitrary strings in HTML.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Re: file case change
by Caillte (Friar) on Mar 15, 2002 at 15:07 UTC

    Changing:

    rename("$path/$_", lc("$path/$_")) or print "Couldn't rename $file: $!\n";

    To

    rename("$path/$_", "$path" . lc("/$_")) or print "Couldn't rename $file: $!\n";

    Would allow upper case letters in your path.

    This page is intentionally left justified.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://151965]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-18 07:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found