0

I was hoping to use a CSV file with a list of file paths in one column and use Python to print the actual files.

We are using Window 7 64-bit.


I have got it to print a file directly:

import os
os.startfile(r'\\fileserver\Sales\Sell Sheet1.pdf, 'print')

The issues comes in when I bring in the CSV file. I think I'm not formatting it correctly because I keep getting:

FileNotFoundError: [WinError2] The system cannot find the file specified: "['\\\\fileserver\\Sales\\Sell Sheet1']"

This is where I keep getting hung up:

import os
import csv
with open (r'\\fileserver\Sales\TestList.csv') as csv_file:
    TestList = csv.reader(csv_file, delimiter=',')
    for row in TestList:
        os.startfile(str(row),'print')

My sample CSV file contains:

\\fileserver\Sales\SellSheet1
\\fileserver\Sales\SellSheet2
\\fileserver\Sales\SellSheet3

Is this an achievable goal?

DrCord
  • 3,917
  • 3
  • 34
  • 47

1 Answers1

2

You shouldn't be using str() there. The CSV reader gives you a list of rows, and each row is a list of fields. Since you just want the first field, you should get that:

os.startfile(row[0], 'print')
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • further to this the OP should be confused about where the extra `['` and `']`are coming from in the error message – Sam Mason May 03 '19 at 21:46