Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

file

Posted on 2006-11-05
10
Medium Priority
?
230 Views
Last Modified: 2010-03-05
is there a command line to make sure file exits or not?
0
Comment
Question by:perlperl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 

Author Comment

by:perlperl
ID: 17878165
should work for both windows and unix
0
 

Author Comment

by:perlperl
ID: 17878202
i cannot use if(-e $filename)
because sometimes i execute my file on remote host....so i need the command line which can work on both unix and windows
0
 
LVL 84

Expert Comment

by:ozo
ID: 17878392
Why do you think that -e does not work on both unix and windows?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:Tintin
ID: 17878542
If you want to check for the existence of a *file*, you are better off using the -f flag.  -e will be true if $filename is a directory, link, device etc.

if (-f $filename)

is 100% portable/compatible across *all* operating systems that Perl runs on (at that's a big list)
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17878545
Please show us what steps you've used to determine it doesn't work on windows and unix servers?  

Putting my ESP hat on, I'm guessing it's a path issue.
0
 

Author Comment

by:perlperl
ID: 17878578
i know u r correct but u didn't get my question....i know -e works on both....
but i m looking for a command line (and not inside the perl script)
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 1600 total points
ID: 17878591
perl -e "print 'file exists' if -f shift" filename
0
 

Author Comment

by:perlperl
ID: 17878595
Excellent!!!
what does shift does??
0
 
LVL 48

Accepted Solution

by:
Tintin earned 400 total points
ID: 17878676
perldoc -f shift

shift shifts the parameter list.  So in ozo's example, the if test if using the shifted parameter, ie: filename
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17878687
Also the following FAQ is relevant

perldoc -q one-liners
Found in /usr/local/lib/perl5/5.8.5/pod/perlfaq3.pod
     Why don't Perl one-liners work on my DOS/Mac/VMS system?

     The problem is usually that the command interpreters on
     those systems have rather different ideas about quoting than
     the Unix shells under which the one-liners were created.  On
     some systems, you may have to change single-quotes to double
     ones, which you must NOT do on Unix or Plan9 systems.  You
     might also have to change a single % to a %%.

     For example:

         # Unix
         perl -e 'print "Hello world\n"'

         # DOS, etc.
         perl -e "print \"Hello world\n\""

         # Mac
         print "Hello world\n"
          (then Run "Myscript" or Shift-Command-R)

         # MPW
         perl -e 'print "Hello world\n"'

         # VMS
         perl -e "print ""Hello world\n"""

     The problem is that none of these examples are reliable:
     they depend on the command interpreter.  Under Unix, the
     first two often work. Under DOS, it's entirely possible that
     neither works.  If 4DOS was the command shell, you'd
     probably have better luck like this:

       perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""

     Under the Mac, it depends which environment you are using.
     The MacPerl shell, or MPW, is much like Unix shells in its
     support for several quoting variants, except that it makes
     free use of the Mac's non-ASCII characters as control
     characters.

     Using qq(), q(), and qx(), instead of "double quotes",
     'single quotes', and `backticks`, may make one-liners easier
     to write.

     There is no general solution to all of this.  It is a mess.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question