0

I am unable to execute the dir command, i get error when specifying the file name all.xml to search and i can't make the search recursive using the /s command , i get the following error cannot access no such file exists and it is not understanding that /s parameter is for searching recursively ,program interprets it as a file path

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

print $vall;
10
  • Is this on windows? You will probably need backslashes. Commented Jun 18, 2017 at 10:12
  • @simbabque yes windows,i can't write backlashes , the cygwin tool in the cmd asks me to write the posix equivalent when i execute the command, i am able to list all the files in rxx folder using forward slashes but i can't recursively find files because /s parameter is interpreted as a file path Commented Jun 18, 2017 at 10:16
  • Put the switch before the path. Commented Jun 18, 2017 at 10:34
  • @simbabque tried that as well it doesn't work if do this dir //server1/dxx/mxx/rss/ , it displays all the files present in 'rss' but when i write the file name and /s , i get the error no such file or directory it also includes file name ui.xml in the path Commented Jun 18, 2017 at 10:41
  • Try -s instead. Sounds weird, but as I remember, Unix like paths also means Unix like options. Commented Jun 18, 2017 at 10:44

1 Answer 1

1

This has nothing to do with Perl. The arguments you are passing to dir are incorrect.

  • dir interprets / as the start of an option unless it's quoted,
  • you have a space in the middle of the path that shouldn't be there, and
  • /s doesn't work with paths containing both / and a file component.

Additionally, you probably want /b in addition to /s.

Fixed:

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

so

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

Example,

>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

That said, I'd personally use File::Find::Rule.

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

my $qfns =
   File::Find::Rule
   ->name('ui.xml')
   ->file
   ->in('//server1/dxx/mxx/rxx');
Sign up to request clarification or add additional context in comments.

9 Comments

no /s is still interpreted as path /s:no such file or directory , and ui.xml is a file which i am trying it search inside rss and its sub directories
i tried the command , and this is the error i got cygwin warning: MS-DOS style path detected: \server1\dxx\mxx\rxx\ui.xml l Preferred POSIX equivalent is: /cygdrive/d/server1/dxx/mxx/rxx/ui.xml CYGWIN environment variable option "nodosfilewarning" turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames dir: cannot access \\\\server1\\dxx\\mxx\\rxx\\ui.xml: N o such file or directory dir: cannot access /s: No such file or directory dir: cannot access /b: No such file or directory
but when i try this ` dir "//server1/dxx/mxx/rxx/" /s i get all the directories under rxx and also cannot access /s :no such directory , `/s' switch is still interpreted as path
You're in a Unix emulation environment, passing a cmd command to sh (where dir appears to be an alias for ls (which means you have an poorly configured shell)). If you want to execute a cmd command, you will need to execute cmd.
i wrote cmd on the command line and then executed the program still doesn't work
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.