SaveAs function doubt

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poolboi
    New Member
    • Jan 2008
    • 170

    SaveAs function doubt

    Hi guys,

    need yr help on a certain command


    $book->SaveAs ("C:\\Docume nts and Settings\\clong \\Desktop\\perl \\$save_file_na me.xls")

    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_nam e.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_nam e.xls" to the directory above even when the folder "perl" is not created?

    thanks
  • eWish
    Recognized Expert Contributor
    • Jul 2007
    • 973

    #2
    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

    Comment

    • nithinpes
      Recognized Expert Contributor
      • Dec 2007
      • 410

      #3
      Originally posted by poolboi
      Hi guys,

      need yr help on a certain command

      $book->SaveAs ("C:\\Docume nts and Settings\\clong \\Desktop\\perl \\$save_file_na me.xls")

      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_nam e.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_nam e.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:

      [CODE=text]

      mkdir("C:\\Docu ments and Settings\\clong \\Desktop\\perl ") unless(-e "C:\\Docume nts and Settings\\clong \\Desktop\\perl ") ;

      [/CODE]

      Comment

      • poolboi
        New Member
        • Jan 2008
        • 170

        #4
        Originally posted by nithinpes
        You can use the folowing line to create directory after checking for its existence:

        [CODE=text]

        mkdir("C:\\Docu ments and Settings\\clong \\Desktop\\perl ") unless(-e "C:\\Docume nts and Settings\\clong \\Desktop\\perl ") ;

        [/CODE]

        Thanks a lot for all yr help
        :)

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Originally posted by nithinpes
          You can use the folowing line to create directory after checking for its existence:

          [CODE=text]

          mkdir("C:\\Docu ments and Settings\\clong \\Desktop\\perl ") unless(-e "C:\\Docume nts and Settings\\clong \\Desktop\\perl ") ;

          [/CODE]

          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.

          Comment

          • poolboi
            New Member
            • Jan 2008
            • 170

            #6
            Originally posted by KevinADC
            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

            Comment

            Working...