Oct-17-2017, 07:28 PM
Hi,
I'm struggling with a problem. I'd like to create a dictionary which looks like this:
Different: when folder size is different after 1 minutes
Same: when folder size is the same after 1 minutes
I'm here so far, which is nothing but scratching the surface.
Here is another attempt:
I'm struggling with a problem. I'd like to create a dictionary which looks like this:
my_dictionary = {'folder1': 'Same', 'folder2': 'Same', 'folder3': 'Different'}folder1, folder2, folder3 etc are the subfolders of the current workdir.
Different: when folder size is different after 1 minutes
Same: when folder size is the same after 1 minutes
I'm here so far, which is nothing but scratching the surface.
import os rootdir = '.' def examine(): return dict(enumerate(next(os.walk(rootdir))[1]))I have a function which returns True or False if a dictionary size has changed, but now I have to apply this to the subdirectories. And I thought a dictionary would be a nice way to do it, but I realised in the meantime that I only know what a dictionary is, but I cannot apply this knowledge to a real working solution... If you could help me out, please do it.
Here is another attempt:
import os import time rootdir = '.' def examine(): while True: try: folders = next(os.walk(rootdir))[1] except StopIteration: print('[-] No such folder') break for f in folders: now = os.path.getsize(f) time.sleep(2) after = os.path.getsize(f) if now == after: print(f + ': Same') else: print(f + ': Different') examine()