naja, ich muss das Programm am Ende auf linux und auch auf Windows ausführen können. Ziel ist es nur Dateien (keine Verzeichnisse) aus einem Pfad in eine "Log Struktur" in der Form Y2008/D25/h23/file.txt zu verschieben oder wahlweise kopieren. Mein Programm läuft wie ich will unter Windows (da hatte ich angefangen, unter Linux läuft das so leider nicht, da ich glob.glob(sys.argv[1]) benutzt habe und z.B. *.* übergeben hatte). Muss weitersuchen wie ich es am geschicktesten anstelle. Hat jemand einen Tipp wie ich auf beiden Betriebssystemen alle Files eines Verzeichnisses in ein Array schreiben kann? Aktuell versuche ich es so:
for root, dirs, files in os.walk('/pfad/'):
print files
Bin leider nicht wirklich fit in python bisher... aber das will ich ändern

Mein Code der unter win aktuell laeuft sieht so aus:
Code: Alles auswählen
import os
import glob
import time
import sys
import shutil
import os
# define a class for easier coding below ;)
class Timestamp:
def __init__(self):
self.filestamp=time.strftime('%Y%m%d%h%m')
self.dirstamp=time.strftime('%Y%m%d%h%m')
if os.name =='nt':
self.dirsplit='\\'
elif os.name == 'posix':
self.dirsplit='/'
print 'Unix like system detected...using "/" for directories'
def gettime(self):
#definition of the timestamp used for files YyyyyMmmDddHhhmmm
self.filestamp='Y'+time.strftime('%Y')+'M'+time.strftime('%m')+'D'\
+time.strftime('%d')+'h'+time.strftime('%H')+'m'+time.strftime('%M') \
+'s'+time.strftime('%S')+'_'
return self.filestamp
def getdirtime(self):
#definition of the timestamp used for files YyyyyMmmDddHhhmmm
self.dirstamp='Y'+time.strftime('%Y')+ self.dirsplit + 'M'+time.strftime('%m')+ self.dirsplit +'D' \
+time.strftime('%d')
return self.dirstamp
def makedir(self):
#definition of foldernames with Yyy\Mmm\Ddd structure
self.dirstamp=self.dirsplit + 'Y'+ time.strftime('%Y')+ self.dirsplit + 'M'\
+time.strftime('%m')+ self.dirsplit + 'D' + time.strftime('%d')
return self.dirstamp
f=Timestamp()
logtimestamp=f.gettime()[:-1]
logdirstamp=f.getdirtime()
if len(sys.argv) == 3:
if not os.path.exists(sys.argv[2] + logdirstamp):
os.makedirs(sys.argv[2] + logdirstamp)
try:
for i in glob.glob(sys.argv[1]):
shutil.copy(i, sys.argv[2] + logdirstamp + f.dirsplit)
print 'copying ' + i + ' to: ' + logdirstamp + os.path.basename(i)
except BaseException:
raise
else:
print 'usage:\tpython copyfilestohist.py "*.*" "d:\\"'