check which file doesn't exist in the file list.

This is the place for queries that don't fit in any of the other categories.

check which file doesn't exist in the file list.

Postby wa110 » Mon Jul 15, 2013 3:35 am

I want to check which com(file) doesn't exist in the file list.

where com is an array list of computer name
the file look something like "capacity_DTCP-TSAIME002_20130512.csv"
At the moment it compare every file with the string(name)
like this
Code: Select all
for com in comList:
   path = 'D:\\StatsScript\\download\\AppStats'
   for files in os.walk('.'):
      for file in files[2]:
         if ( str(file).lower() == ("capacity_" + com + "_" + str(d.strftime('%Y%m%d')) + ".csv" ).lower() ):
            infile = csv.reader(open(file,"r"))
            fb = open(file,"r")

Since I know the exact name of the coputer
e.g. comList = ['US1S-TSDAAPP01', 'US1S-TSDAAPP02', 'US1S-TSDAAPP03', 'US1S-TSDAAPP04']
Im want to do something like this
path = 'D:\\StatsScript\\download\\AppStats\\"capacity_" + com + "_" + str(d.strftime('%Y%m%d')) + ".csv'
which might make my program run faster, however it doesn't let me use this kind of syntax.

Posts: 1
Joined: Mon Jul 15, 2013 3:26 am

Re: check which file doesn't exist in the file list.

Postby metulburr » Mon Jul 15, 2013 4:57 am

path = 'D:\\StatsScript\\download\\AppStats\\"capacity_" + com + "_" + str(d.strftime('%Y%m%d')) + ".csv'

your string starts and stops throughout the whole thing. It is not one full string, a thus gives a syntax error

Use raw strings, and use the format method to insert a value into the string. You can concatenate them, but you are not doing it correctly.
Code: Select all
import time

path = 'D:\\StatsScript\\download\\AppStats\\capacity_com_{}.csv'.format(
we will be moving to on October 1 2016
more details here
User avatar
Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 9 guests