Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-13-2002, 02:32 PM   PM User | #1
amy2go
New Coder

 
Join Date: Jun 2002
Location: Dallas
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
amy2go is an unknown quantity at this point
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.
amy2go is offline   Reply With Quote
Old 08-13-2002, 11:26 PM   PM User | #2
Mouldy_Goat
Regular Coder

 
Join Date: Jul 2002
Location: London, UK
Posts: 126
Thanks: 0
Thanked 0 Times in 0 Posts
Mouldy_Goat is an unknown quantity at this point
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.
Mouldy_Goat is offline   Reply With Quote
Old 08-14-2002, 01:57 PM   PM User | #3
amy2go
New Coder

 
Join Date: Jun 2002
Location: Dallas
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
amy2go is an unknown quantity at this point
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.
amy2go is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:27 PM.


Advertisement
Log in to turn off these ads.