I am writing and testing code on XPsp3 w/ python 2.7. I am running the code on 2003 server w/ python 2.7. My dir structure will look something like this
d:\ssptemp
d:\ssptemp\ssp9-1
d:\ssptemp\ssp9-2
d:\ssptemp\ssp9-3
d:\ssptemp\ssp9-4
d:\ssptemp\ssp10-1
d:\ssptemp\ssp10-2
d:\ssptemp\ssp10-3
d:\ssptemp\ssp10-4
Inside each directory there is one or more files that will have "IWPCPatch" as part of the filename.
Inside one of these files (one in each dir), there will be the line 'IWPCPatchFinal_a.wsf'
What I do is
1) os.walk across all dirs under d:\ssptemp
2) find all files with 'IWPCPatch' in the filename
3) check the contents of the file for 'IWPCPatchFinal_a.wsf'
4) If contents is true I add the path of that file to a list.
My problem is that on my XP machine it works fine. If I print out the results of the list I get several items in the order I listed above.
When I move it to the server 2003 machine I get the same contents in a different order. It comes ssp10-X, then ssp9-X. And this is causing me issues with a different area in the program.
I can see from my output that it begins the os.walk in the wrong order, but I don't know why that is occuring.
import os
import fileinput
print "--createChain--"
listOfFiles = []
for path, dirs, files in os.walk('d:\ssptemp'):
print "parsing dir(s)"
for file in files:
newFile = os.path.join(path,file)
if newFile.find('IWPCPatch') >= 0:
for line in fileinput.FileInput(newFile):
if "IWPCPatchFinal_a.wsf" in line:
listOfFiles.append(newFile)
print "Added", newFile
for item in listOfFiles:
print "list item", item
for path, dirs, files in os.walk('d:\ssptemp'):
# sort dirs and files
dirs.sort()
files.sort()
print "parsing dir(s)"
# ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With