Advertisement
robertvari

Eszter Haszon-Hegedüs

Apr 18th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. #mappa tartalmat kilistázza méret és dátum adatokkal együtt txt file-ba
  2.  
  3. import os, datetime
  4.  
  5. foldername = input("Enter the folder name:")                #csak pontos útvonal adható!
  6. folderPath = foldername
  7.  
  8. # string változó előkészítése
  9. finalText = ""
  10.  
  11. if os.path.exists(folderPath):
  12.     filelist = os.listdir(folderPath)
  13.     for i in filelist:
  14.         size = int((os.path.getsize(folderPath + "/" + i))/1024)        #csak mappa méret tartalom nélkül?
  15.         creation_date = datetime.datetime.fromtimestamp(os.path.getctime(folderPath + "/" + i))
  16.  
  17.         # itt adjuk hozzá a finalText-hez
  18.         finalText += "File: {}, \tSize: {} kB, \tCreation date: {}\n".format(i, size, creation_date)
  19. else:
  20.     print("no results")
  21.  
  22. # ezt jobb egyben kiírni ha megvan a finalText
  23. with open(folderPath + "/filelist.txt", "w") as f:
  24.     f.write(finalText)
  25.  
  26. # elég csak a string-et printelni
  27. print(finalText)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement