Checking to see if a paticular file exists

Discussion in 'Perl Misc' started by vijay, Feb 2, 2004.

  1. vijay

    vijay Guest

    Hi
    I'm trying to check to see if a paticular file exist on the machine,
    i'm unable to check for files insides directories which have space in
    between their names, If i run the script from the command prompt they
    seem to run fine, but when i try to open the script on a browser, it
    is not able to even open the directory, i get a Invalid Argument
    Error,This does not happen for directories which do not have a space
    in their name.Any help is greatly appreciated
    Sincerly
    Vijay
    vijay, Feb 2, 2004
    #1
    1. Advertising

  2. (vijay) writes:
    > I'm trying to check to see if a paticular file exist on the machine,
    > i'm unable to check for files insides directories which have space in
    > between their names, If i run the script from the command prompt they
    > seem to run fine, but when i try to open the script on a browser, it
    > is not able to even open the directory, i get a Invalid Argument
    > Error


    perldoc -q 500

    <wavy lines>
    use PSI::ESP;

    print <<EOGUESS;

    I bet you're not using CGI.pm, and you're not decoding URI-encoded
    entities properly. After you've followed all the directions in the
    FAQ I just referred you to, try creating a small CGI program, using
    CGI.pm, that just prints out "It exists", or "It doesn't exist" when
    you pass a filename as a parameter. It shouldn't take more than 10
    lines. Doing this will probably help you debug your problem.

    EOGUESS
    __END__
    </wavy lines>


    -=Eric
    --
    Come to think of it, there are already a million monkeys on a million
    typewriters, and Usenet is NOTHING like Shakespeare.
    -- Blair Houghton.
    Eric Schwartz, Feb 2, 2004
    #2
    1. Advertising

  3. In article <>,
    vijay <> wrote:
    : I'm trying to check to see if a paticular file exist on the machine,
    :i'm unable to check for files insides directories which have space in
    :between their names, If i run the script from the command prompt they
    :seem to run fine, but when i try to open the script on a browser, it
    :is not able to even open the directory, i get a Invalid Argument
    :Error,This does not happen for directories which do not have a space
    :in their name.Any help is greatly appreciated

    How are you passing the directory name in to the CGI script? If you
    are passing it through the GET method (i.e, the directory name
    is part of the URL) then make sure that you replace each space
    with the character triple %20 -- .e.g,

    http://www.yahoo.com/~vijaysenthilv/cgi-bin/checkfile/hi there #wrong
    http://www.yahoo.com/~vijaysenthilv/cgi-bin/checkfile/hi there #better
    --
    Live it up, rip it up, why so lazy?
    Give it out, dish it out, let's go crazy, yeah!
    -- Supertramp (The USENET Song)
    Walter Roberson, Feb 2, 2004
    #3
  4. vijay <> wrote:

    > I'm trying to check to see if a paticular file exist on the machine,



    Show us your code that is trying to check to see if a paticular file
    exist on the machine, and we will help you fix it.


    > If i run the script from the command prompt they
    > seem to run fine, but when i try to open the script on a browser, it

    ^^^^^^^
    > is not able to even open the directory, i get a Invalid Argument


    perldoc -q browser

    My CGI script runs from the command line but not the browser. (500
    Server Error)


    > Any help is greatly appreciated



    Any code is greatly appreciated.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Feb 2, 2004
    #4
  5. vijay wrote:
    > I'm trying to check to see if a paticular file exist on the machine,


    See "perldoc -f -e"

    > i'm unable to check for files insides directories which have space in
    > between their names, If i run the script from the command prompt they
    > seem to run fine,


    Then chances are your problem is _not_ a Perl problem. Please see
    "perldoc -q 500"

    > but when i try to open the script on a browser,


    How do you "open a script on a browser"?

    > it
    > is not able to even open the directory, i get a Invalid Argument
    > Error,
    > This does not happen for directories which do not have a space
    > in their name.Any help is greatly appreciated


    Well, quite impoossible to do without seeing your code (or actually a
    minimal example that exposes the problem).

    jue
    Jürgen Exner, Feb 3, 2004
    #5
  6. vijay

    vijay Guest

    Hi
    I'm sorry i should have posted the code
    __________________________________________________
    require "cgi-lib.pl";
    print "Content-type: text/html\n\n";



    if (!(-e 'J:\DWGS\parking\LOT-10.dwg')) {
    print "Not working----"
    }

    else {
    print "working---";
    }



    if (!(-e 'J:\DWGS\Project Archive\911-001-1922-A-002-AB.pdf')) {
    print "Not working----"
    }

    else {
    print "working---";
    }
    ____________________________________________________________________


    The above code prints working and working when i run it from the DOS
    promt but prints working and Not working when i open it in a browser,
    i Did try using the %20 and forward slash format but that didnt help
    either


    Thanks
    Sincerly vijay
    vijay, Feb 3, 2004
    #6
  7. vijay

    Brad Baxter Guest

    On Tue, 3 Feb 2004, vijay wrote:
    > The above code prints working and working when i run it from the DOS
    > promt but prints working and Not working when i open it in a browser,
    > i Did try using the %20 and forward slash format but that didnt help
    > either


    I suspect your question is a variation of this faq:

    My CGI script runs from the command line but not the browser.

    That is, I think you have a CGI question rather than a Perl question.

    Regards,

    Brad
    Brad Baxter, Feb 3, 2004
    #7
  8. vijay

    gnari Guest

    "vijay" <> wrote in message
    news:...

    > require "cgi-lib.pl";
    > print "Content-type: text/html\n\n";


    I am not going to mention strict, warnings and CGI.pm now,
    but I might next time.

    > ...
    > if (!(-e 'J:\DWGS\parking\LOT-10.dwg')) {
    > ...
    > if (!(-e 'J:\DWGS\Project Archive\911-001-1922-A-002-AB.pdf')) {
    > ...
    > i Did try using the %20 and forward slash format but that didnt help
    > either


    the %20 does not apply in your case.

    does the problem go away if you rename away the space ?
    does the first filepath fail if you rename a space into it?

    maybe it is a permission problem. the user executing the script
    as cgi is not the same as the one in the shell. and their environments
    differ as well.

    gnari
    gnari, Feb 3, 2004
    #8
  9. On Tue, 03 Feb 2004 11:46:13 -0800, vijay wrote:

    > Hi
    > I'm sorry i should have posted the code
    > __________________________________________________
    > require "cgi-lib.pl";

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    Please tell me this is something *you* wrote and not the old Perl4 CGI
    library ......

    If it's the latter, *please* consider using the CGI module .....

    --
    Jim

    Copyright notice: all code written by the author in this post is
    released under the GPL. http://www.gnu.org/licenses/gpl.txt
    for more information.

    a fortune quote ...
    "We are upping our standards ... so up yours." -- Pat Paulsen
    <for President, 1988.
    James Willmore, Feb 4, 2004
    #9
  10. vijay

    vijay Guest

    "gnari" <> wrote in message news:<bvp1ni$14i$>...
    > "vijay" <> wrote in message
    > news:...
    >
    > > require "cgi-lib.pl";
    > > print "Content-type: text/html\n\n";

    >
    > I am not going to mention strict, warnings and CGI.pm now,
    > but I might next time.
    >
    > > ...
    > > if (!(-e 'J:\DWGS\parking\LOT-10.dwg')) {
    > > ...
    > > if (!(-e 'J:\DWGS\Project Archive\911-001-1922-A-002-AB.pdf')) {
    > > ...
    > > i Did try using the %20 and forward slash format but that didnt help
    > > either

    >
    > the %20 does not apply in your case.
    >
    > does the problem go away if you rename away the space ?

    Yes it does go away

    > does the first filepath fail if you rename a space into it?

    Yes it fails
    >
    > maybe it is a permission problem. the user executing the script
    > as cgi is not the same as the one in the shell. and their environments
    > differ as well.


    I get a invalid Argument error when i try to opendir command on
    directories with space in their file name.I guess its a CGI error than
    something to deal with perl, i'll try searching CGI sites to see if i
    can come up with a fix
    Thanks
    Vijay

    >
    > gnari
    vijay, Feb 4, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CES
    Replies:
    2
    Views:
    843
    .NET Follower
    Feb 13, 2004
  2. Darrel
    Replies:
    4
    Views:
    3,599
    darrel
    Dec 10, 2004
  3. Steveo
    Replies:
    2
    Views:
    5,667
    Michiel Konstapel
    Sep 17, 2003
  4. Totan
    Replies:
    0
    Views:
    919
    Totan
    Apr 17, 2006
  5. Daz
    Replies:
    3
    Views:
    191
Loading...

Share This Page