|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am trying to gather some statistics and print the contents of all the files in a particular directory. Everything works fine for alphanumeric filenames, however the filenames with whitespace are causing me some grief.
Could somebody give me some pointers or solution to dealing with " file name .text"? thanks |
|
#2
|
|||
|
|||
|
jjk,
im not sure what you are looking to do? if it is remove the spaces, then try this: $file = ' file .txt" $file=~ s/\s//; if that does not work, try this: $file=~ s/ //; hope this helps |
|
#3
|
|||
|
|||
|
Thanks randor, that's not exactly what I'm trying to do, I don't think I was really sure either. I believe now what I am trying to do is open a filehandle with spaces in the filename and I get "Read on closed filehandle" error on the statement
open(SOMEFILE, "$filename"); where $filename = "\x20filename" thanks |
|
#4
|
|||
|
|||
|
Thanks randor, that's not exactly what I'm trying to do, I don't think I was really sure either. I believe now what I am trying to do is open a filehandle with spaces in the filename and I get "Read on closed filehandle" error on the statement
open(SOMEFILE, "$filename"); where $filename = "\x20filename" thanks |
|
#5
|
|||
|
|||
|
You'll need to show us more code than just the open() command if you want us to know what it does.
|
|
#6
|
|||
|
|||
|
Source code as requested. Any suggestions for improvement are welcome.
The objective is to produce a list of filenames in a directory in the format "filename, creation time (I know this gives mtime), file contents. My other thought is if I can't get around the open file with spaces_in_the_filename problem, change the filename. Thoughts? $srcdir = $ARGV[0]; chdir($srcdir) || die "Cannot change directory to $srcdir: $!"; opendir(DATA, ".") || die "Cannot open directory $srcdir : $!"; foreach $filename (grep !/^\./, readdir(DATA)) { $a = <STDIN>; open(SOMEFILE, "<$filename"); while (<SOMEFILE>) { $fdate = localtime((stat($filename))[9]); print "$filename $fdate $_ \n"; } } closedir(DATA); thanks in advance |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Filenames with spaces |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|