Xavier Oddmon
December 24th, 2009, 02:11 AM
Hello! I am writing a program to batch rename files as a way to learn how to make graphical interfaces with perl. In the interface, the user selects a directory to work in, and it is supposed to list all of the files. It is not supposed to list directories. However, it is behaving in a way I can't quite explain. Here's the structure of the directory i'm working in.
Perl
|-- renamer
| |-- DIR
| | |-- a.txt
| | |-- b.txt
| | |-- c.txt
| | `-- MY
| |-- Directory With Spaces
| | `-- <Contains many many files>
| |--rename.pl
| |--rename.pl~
| `--window.glade
`-- test
|-- FIFO
`-- Stopwatch
Now, when i point it to "renamer", it just lists rename.pl, rename.pl~, and window.glade. However, when I point it to DIR, it lists a.txt, b.txt, c.txt, and MY. It should not list MY. (It also doesn't help if there are files in MY).
Here's the code that's handling the displaying of that folder.
foreach $f (@allthings)
{
if (-d $f)
{
print "$f is a directory\n";
}
else
{
print "pushing $f\n";
push @allfiles, $f;
$list = "$list$f\n";
}
}
And finally, for completeness, here's the output in the terminal:
chris@chris-laptop:~/Perl/renamer$ perl rename.pl
pushing rename.pl
pushing rename.pl~
DIR is a directory
.. is a directory
. is a directory
Directory With Spaces is a directory
pushing window.glade
--note: this is where i changed directory to "MY"
pushing a.txt
.. is a directory
pushing b.txt
. is a directory
pushing c.txt
pushing MY
This happens on and off all over my filesystem. What's going on:confused: This is very frustrating.
Perl
|-- renamer
| |-- DIR
| | |-- a.txt
| | |-- b.txt
| | |-- c.txt
| | `-- MY
| |-- Directory With Spaces
| | `-- <Contains many many files>
| |--rename.pl
| |--rename.pl~
| `--window.glade
`-- test
|-- FIFO
`-- Stopwatch
Now, when i point it to "renamer", it just lists rename.pl, rename.pl~, and window.glade. However, when I point it to DIR, it lists a.txt, b.txt, c.txt, and MY. It should not list MY. (It also doesn't help if there are files in MY).
Here's the code that's handling the displaying of that folder.
foreach $f (@allthings)
{
if (-d $f)
{
print "$f is a directory\n";
}
else
{
print "pushing $f\n";
push @allfiles, $f;
$list = "$list$f\n";
}
}
And finally, for completeness, here's the output in the terminal:
chris@chris-laptop:~/Perl/renamer$ perl rename.pl
pushing rename.pl
pushing rename.pl~
DIR is a directory
.. is a directory
. is a directory
Directory With Spaces is a directory
pushing window.glade
--note: this is where i changed directory to "MY"
pushing a.txt
.. is a directory
pushing b.txt
. is a directory
pushing c.txt
pushing MY
This happens on and off all over my filesystem. What's going on:confused: This is very frustrating.