2017-06-18 112 views
0

我無法執行dir命令,我在指定文件名all.xml時發生錯誤,並且我無法使用/s命令進行搜索遞歸,我得到以下錯誤cannot access no such file exists並且不理解是/s參數是遞歸搜索,程序將其解釋爲文件路徑無法從perl腳本傳遞參數到dir命令

use strict; 
use warnings; 
print "i"; 
my $vall = ` dir //server1/dxx/mxx/rxx/ "ui.xml" /s`; 

print $vall; 
+0

這是在Windows上嗎?你可能需要反斜槓。 – simbabque

+0

@simbabque是windows,我不能寫反斜槓,cmd中的cygwin工具要求我寫相當於posix的命令時,我能夠使用正斜槓列出rxx文件夾中的所有文件,但是我不能遞歸查找文件,因爲'/ s'參數被解釋爲文件路徑 – PopCorn

+0

將開關置於路徑之前。 – simbabque

回答

1

這有什麼做用Perl。您傳遞給dir的參數不正確。

  • dir解釋/作爲一個選項的開始,除非它的報價,
  • 你必須在不應該出現在路中間的空間,
  • /s不工作的路徑包含/和一個文件組件。

此外,除了/s之外,您可能還需要/b

修正:

dir "\\server1\dxx\mxx\rxx\ui.xml" /s/b 

所以

my $dir_output = `dir "\\\\server1\\dxx\\mxx\\rxx\\ui.xml" /s/b`; 

例,

>dir "//localhost/C$/Users/ikegami/Desktop/" /s/b 
\\localhost\C$\Users\ikegami\Desktop\a.jpg 
\\localhost\C$\Users\ikegami\Desktop\cabinet.txt 
... 

>dir "//localhost/C$/Users/ikegami/Desktop/a.jpg" /s/b 
File Not Found            <-- WTF? 

>dir "\\localhost\C$\Users\ikegami\Desktop\a.jpg" /s/b 
\\localhost\C$\Users\ikegami\Desktop\a.jpg 
\\localhost\C$\Users\ikegami\Desktop\x\a.jpg 

>dir \\localhost\C$\Users\ikegami\Desktop\a.jpg /s/b 
\\localhost\C$\Users\ikegami\Desktop\a.jpg 
\\localhost\C$\Users\ikegami\Desktop\x\a.jpg 

>type a.pl 
print `dir \\\\localhost\\C\$\\Users\\ikegami\\Desktop\\a.jpg /s/b` 

>perl a.pl 
\\localhost\C$\Users\ikegami\Desktop\a.jpg 
\\localhost\C$\Users\ikegami\Desktop\x\a.jpg 

這麼說,我會親自使用File::Find::Rule

use File::Find::Rule qw(); 

my $qfns = 
    File::Find::Rule 
    ->name('ui.xml') 
    ->file 
    ->in('//server1/dxx/mxx/rxx'); 
+0

no'/ s'仍然被解釋爲路徑'/ s:沒有這樣的文件或目錄',並且'ui.xml'是一個文件,我正在嘗試它在'rss'及其子目錄中搜索 – PopCorn

+0

我試過命令,這是我得到的錯誤'cygwin警告: 檢測到的MS-DOS樣式路徑:\ server1 \ dxx \ mxx \ rxx \ ui。xml l 首選的POSIX等價物是:/cygdrive/d/server1/dxx/mxx/rxx/ui.xml CYGWIN環境變量選項「nodosfilewarning」關閉此警告。 有關POSIX路徑的更多詳細信息,請參閱用戶指南: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames dir:無法訪問\\\\ server1 \\ dxx \\ mxx \\ rxx \\ ui.xml:N ○這樣的文件或目錄 dir:無法訪問/ s:沒有這樣的文件或目錄 dir:無法訪問/ b:沒有這樣的文件或目錄 – PopCorn

+0

但是當我嘗試這個' 'dir「// server1/dxx/mxx/rxx /」/ s'我得到rxx下的所有目錄並且'不能訪問/ s:沒有這樣的目錄','/ s'開關仍然被解釋爲路徑 – PopCorn