Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^3: Renaming non-ascii files

by JamesNC (Chaplain)
on Jun 01, 2005 at 13:20 UTC ( #462423=note: print w/replies, xml ) Need Help??

in reply to Re^2: Renaming non-ascii files
in thread Renaming non-ascii files

Try using the file test operators -B or -T to test for binary or text file perldoc -f -B. rename works for me on XP and 5.8.4 and works on both binary and plain text. Use a one liner and prove it to yourself  perl -le "rename 'somefile.xls', 'somefile2.xls'" I would suggest learning more about glob and the file test operators. I usually glob a list of files from the directory I want and then operate on the resulting list. There are lots of other ways to do this. Perhaps a simle example will get you started:
my (@files) = glob "c:/progs/*"; #list of progs my (@dirs, @binfiles, @textfiles); foreach my $f( @files ) { -d $f ? push @dirs, $f : -f $f && -B $f ? push @binfiles, $f : -f $f && -T $f ? push @textfiles, $f : next; }


Replies are listed 'Best First'.
Re^4: Renaming non-ascii files
by Corion (Pope) on Jun 02, 2005 at 09:54 UTC

    Please note that glob is a byzantine way of finding files and it relies heavily on the idea that no part of the glob pattern will contain a space. That idea is prevalent in much of the Unix mindset, but it easily fails on Win32 (unless you start and take care to quote the whitespace).

    If you're sure that your paths cannot and will not contain spaces, glob is convenient to use. If there is the possibility that the patterns will contain spaces, I found it more convenient to use File::Find (or File::Find::Rule) right from the start.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2021-04-10 15:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found