我想从文本文件发送文件路径到变量。然后我想使用该文件路径并打开它并列出其中的目录。不能opendir“没有这样的文件或目录”在Perl
open (FILE, 'drive_path.txt') or die $!;
my $dir= (<FILE>);
close (FILE);
chomp $dir;
print $dir;
opendir (DIR, '$dir') or die $!;
打印输出给了我正确的路径位置:
C:\Documents and Settings\KSoli7151794\Desktop\TEST
但由于某些原因,它说:“没有这样的文件或目录” 任何帮助吗?
编辑:这是我的桌面文件列表: 卷在驱动器C的操作系统驱动器 卷序列号是18C9-6274
目录的C:\ Documents和Settings \ KSoli7151794 \桌面
10/04/2013 11:35 AM <DIR> .
10/04/2013 11:35 AM <DIR> ..
11/18/2010 11:27 AM 587,776 7za.exe
10/04/2013 11:31 AM 51 drive_path.txt
10/03/2013 05:39 PM 1,494 ExtractAndCreate.bat
09/27/2013 04:34 PM 604 ExtractAndDelete.bat
10/04/2013 11:30 AM 1,854 ParseAndRename.pl
08/07/2013 11:38 AM <DIR> Resources
10/04/2013 11:06 AM <DIR> TEST
10/04/2013 11:35 AM 0 test.txt
8 File(s) 995,380 bytes
4 Dir(s) 285,785,993,216 bytes free
新代码与错误消息:
open (FILE, 'drive_path.txt') or die $!;
my $dir= (<FILE>);
close (FILE);
chomp $dir;
print $dir;
opendir (DIR, $dir) or die $!;
C:\Documents and Settings\KSoli7151794\Desktop\TEST
Invalid argument at ParseandRename.pl line 18
首先18行
#!/usr/local/bin/perl
use strict;
use warnings;
open (FILE, 'drive_path.txt') or die $!;
local $/;
my $blocksize;
my $directory;
my $testcase;
my $count = -1;
my @foldernames;
my @testsuite;
my $dir = (<FILE>);
close (FILE);
chomp $dir;
print $dir;
opendir (DIR, $dir) or die $!;
SOLUTION: 我拿出local$/;
,它似乎按预期工作。
后第18行ParseandRename.pl' – toolic
的'见我的回答此更新。 – toolic