Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    Dallas
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing directories

    Okay, hopefully there is a simple answer to this...there usually is, right? I am saving data as .csv files (comma-separated) to be opened later in Excel. That part works. But when I change directories using chdir(), it DOES NOT work if I use "C:\". However, it DOES work if I use another drive that I am mapped to, such as "S:\". Why is that, and how can I fix it? Btw, when chdir() doesn't work, it still saves to the cgi-bin directory. Here's the test code...very short:

    #!c:\perl\bin\perl.exe
    use CGI qw( :standard );

    $drive="C:\Intranet";
    chdir($drive);

    print "Opening file for output:\n";
    open (FILE, ">file.csv") or die ("Can't find file.csv : $!");
    print "Outputting to file.\n";
    print (FILE "This,is,a,comma\nseparated,file\n");
    close FILE or die "Can not close file.csv : $!";
    Some days you are the bug; some days you are the windshield.

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You don't really need to change the working directory here, perhaps you could try something like this instead....

    Code:
    #!c:/perl/bin/perl.exe
    use CGI qw( :standard ); 
    
    $file = "C:/Intranet/file.csv"; 
    
    print header; # It shouldn't work without this.. 
    print "Opening file for output:\n"; 
    open (FILE, ">$file") or die ("Can't find $file: $!"); 
    print "Outputting to file.\n"; 
    print FILE "This,is,a,comma\nseparated,file\n"; 
    close FILE or die "Can not close $file: $!";
    By the way I noticed you were using single backslashes for the path. Since in Perl a single backslash means it should be expecting a metacharacter, it won't interpret it correctly. In a Windows environment you have two options for file separators. You can either do a double backslash or a single forward slash - i.e. *NIX style. I go for the second since it's more portable..

    Anyway, hope I helped a bit.

  • #3
    New Coder
    Join Date
    Jun 2002
    Location
    Dallas
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You’re a genius! Thank you, thank you. And that's exactly what I needed anyway, because I would like the user to be able to specify where they want the file to be placed.

    Amy
    Some days you are the bug; some days you are the windshield.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •