Hi,
I have a tried-and-true python script/program for converting txt files to xls. It is time to automate and all goes well until I try to save a converted .xls file to a network location other than the location I am running from.
Specs
Python 2.5.4
xlwt 0.7.4
Source:
Windows 7 Enterprise Build 7601 SP1
or
Windows Server 2008R2 Standard
Target:
Same machine, either PC or server- works
Different Server using UNC, either with server name or mapped drive (no shares)- fails
I have access to all Targets, as I am able to copy the input file to the same location, and am running as the same user. Also the program is finding the correct location, as it is calculating the correct Output file name.
I eliminated other factors, such as calling application and script, by calling the prog directly from the command line with full pathname in the parameter value.
I also tried '/' chars
The output file is very small, 30K.
Code Summary
#Output location and filename will be the same as input with xls extension
outputFile = ''.join(sys.argv[1])
#replace blanks with underscore in output file name
outputFile = outputFile.replace(" ", "_")
#replace .xls with .txt in output file name
outputFile = outputFile.replace(".txt", ".xls")
print " Input file: ", sys.argv[1]
print " Output file: ", outputFile
book = xlwt.Workbook()
.
conversion
.
#Below is line 383
book.save(outputFile)
Works
Command: progname.py "C:\RootFolder\env\Filename.txt"
Output:
Input file: C:\RootFolder\env\Filename.txt
Output file: C:\RootFolder\env\Filename.xls
Note: Converted .xls file is available
OR
Command: progname.py "I:\RootFolder\env\Module\Filename.txt"
Output:
Input file: I:\RootFolder\env\Module\Filename.txt
Output file: I:\RootFolder\env\Module\Filename.xls
Note: displays are also correct here.
File "C:\<loc of prog>\progname.py", line 383, in <module>
book.save(outputFile)
File "C:\Python25\lib\site-packages\xlwt\Workbook.py", line 643, in save
doc.save(filename, self.get_biff_data())
File "C:\Python25\lib\site-packages\xlwt\CompoundDoc.py", line 262, in save
f = open(file_name_or_filelike_obj, 'w+b')
IOError: [Errno 2] No such file or directory: 'I:\\RootFolder\\env\\Module\\Filename.xls'
Thanks for this group!