Write a python program to list all files in the given directory along with their length and last modification time. The output should contain one line for each file containing filename, length and modification date separated by tabs. https://www.tutorialspoint.com/python/python_modules.htm
Thanks for the question. Below is the code you will be needing Let me know if you have any doubts or if you need anything to change. Thank You !! ================================================================================================== import os, datetime def listDirectory(path): if os.path.isdir(path): print('Valid Directory') arr = os.listdir(path) for file in arr: filename=path+'\\'+file if (os.path.isfile(filename)): print('File Name: {}'.format(file),end=' ') print('File Size: {} bytes'.format(os.path.getsize(filename)),end=' ') time =os.path.getmtime(filename) print('File Last Modified on: {}'.format(datetime.datetime.fromtimestamp(time))) else: print('Invalid Directory provided.') def main(): directory = input('Enter directory path: ') listDirectory(directory) if __name__ == '__main__': main()
=======================================================================================
Get Answers For Free
Most questions answered within 1 hours.