By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,851 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,851 IT Pros & Developers. It's quick & easy.

SaveAs function doubt

100+
P: 170
Hi guys,

need yr help on a certain command


$book->SaveAs ("C:\\Documents and Settings\\clong\\Desktop\\perl\\$save_file_name.xl s")

the above statement in perl save my file to the directory in my desktop as "perl"
however the problem with the statement is if the file "perl" exist the file contain my program "$save_file_name.xls" exists then,

but when the folder perl is not created, this SaveAs function doesn't seem to able to create a new folder "perl" by itself, instead it saves to a default directory, how do i actually then save "$save_file_name.xls" to the directory above even when the folder "perl" is not created?

thanks
Feb 12 '08 #1
Share this Question
Share on Google+
5 Replies


eWish
Expert 100+
P: 971
If the module you are using does not have an alternative solution you could always do a test and see if the directory exists. If the directory does not exists then just create it before you save the file.

perldoc -X

--Kevin
Feb 12 '08 #2

nithinpes
Expert 100+
P: 410
Hi guys,

need yr help on a certain command

$book->SaveAs ("C:\\Documents and Settings\\clong\\Desktop\\perl\\$save_file_name.xl s")

the above statement in perl save my file to the directory in my desktop as "perl"
however the problem with the statement is if the file "perl" exist the file contain my program "$save_file_name.xls" exists then,

but when the folder perl is not created, this SaveAs function doesn't seem to able to create a new folder "perl" by itself, instead it saves to a default directory, how do i actually then save "$save_file_name.xls" to the directory above even when the folder "perl" is not created?

thanks

You can use the folowing line to create directory after checking for its existence:

Expand|Select|Wrap|Line Numbers
  1.  
  2. mkdir("C:\\Documents and Settings\\clong\\Desktop\\perl") unless(-e "C:\\Documents and Settings\\clong\\Desktop\\perl") ;
  3.  
  4.  
Feb 12 '08 #3

100+
P: 170
You can use the folowing line to create directory after checking for its existence:

Expand|Select|Wrap|Line Numbers
  1.  
  2. mkdir("C:\\Documents and Settings\\clong\\Desktop\\perl") unless(-e "C:\\Documents and Settings\\clong\\Desktop\\perl") ;
  3.  
  4.  

Thanks a lot for all yr help
:)
Feb 12 '08 #4

KevinADC
Expert 2.5K+
P: 4,059
You can use the folowing line to create directory after checking for its existence:

Expand|Select|Wrap|Line Numbers
  1.  
  2. mkdir("C:\\Documents and Settings\\clong\\Desktop\\perl") unless(-e "C:\\Documents and Settings\\clong\\Desktop\\perl") ;
  3.  
  4.  

You don't really need the test. Either the directory will be created or it won't. The problem with that code is if the mkdir() function fails and the directory does not exist, you will never know what happened. Might be a small chance of that happening but it is a good habit to always check the success/failure of system level functions.
Feb 12 '08 #5

100+
P: 170
You don't really need the test. Either the directory will be created or it won't. The problem with that code is if the mkdir() function fails and the directory does not exist, you will never know what happened. Might be a small chance of that happening but it is a good habit to always check the success/failure of system level functions.
hm..ok thanks
but in any case
the code mkdir() works in my program now..so it's able to create a folder and save an excel file inside
Feb 12 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.