Question

Write a python program to list all files in the given directory along with their length...

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

Homework Answers

Answer #1
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()

=======================================================================================

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please do the following in python: Write a program (twitter_sort.py) that merges and sorts two twitter...
Please do the following in python: Write a program (twitter_sort.py) that merges and sorts two twitter feeds. At a high level, your program is going to perform the following: Read in two files containing twitter feeds. Merge the twitter feeds in reverse chronological order (most recent first). Write the merged feeds to an output file. Provide some basic summary information about the files. The names of the files will be passed in to your program via command line arguments. Use...
Python Programming Build a python programming that asks the user for a three-letter substring. The program...
Python Programming Build a python programming that asks the user for a three-letter substring. The program should then proceed to read the file strings.txt. Each line in strings.txt will contain a string. Your program should then test to see how many non-overlapping occurrences of the three-letter substring occur in that string and test whether the string is a palindrome. The program should then proceed to create an output file string_stats.txt, which contains the original data on one line and the...
I need python code for this. Write a program that inputs a text file. The program...
I need python code for this. Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Uppercase words should take precedence over lowercase words. For example, 'Z' comes before 'a'. The input file can contain one or more sentences, or be a multiline list of words. An example input file is shown below: example.txt the quick brown fox jumps over the lazy dog An example of the program's output...
IN PYTHON : Write a program that asks the user for a number. Write the number...
IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be...
Develop an Algorithm and java program using Design Recipe: 1) Develop a java program to the...
Develop an Algorithm and java program using Design Recipe: 1) Develop a java program to the content of one file to another. Hint 1: read() Hint 2: write() 2) Develop a java program to List all files in a given directory. Hint: list()
[Python] what are the program solutions to the promts? Write a program to determine which word...
[Python] what are the program solutions to the promts? Write a program to determine which word is the shortest of the following: apple, banana, peach, plum, grapefruit. Write a program to determine the average number given in a list. The first line of your program should give a name to a list to be averaged: e.g numbers = [3,17,1,44,239]
Write a python program that will perform text analysis on an input text using all of...
Write a python program that will perform text analysis on an input text using all of the following steps: 1. Take the name of an input file as a command line argument. For example, your program might be called using python3 freq.py example1 to direct you to process a plain text file called example. More information is given on how to do this below. 2. Read the contents of the file into your program and divide the text into a...
Write a Python program prints out the unique elements of a list lst in a sorted...
Write a Python program prints out the unique elements of a list lst in a sorted manner (i.e it removes duplicates from the list). For example, if list is [10,20,30,20,10,50,60,40,80,50,40], the output should be [10, 20, 30, 40, 50, 60, 80].?
Using the facilities of numpy, write a python program that reads the input signal as a...
Using the facilities of numpy, write a python program that reads the input signal as a space separated sequence of numbers on one line, and the system impulse response as a space separated sequence of numbers on the next line, and outputs (on one line) the output of the DT LTI system. The input lines should be interpreted as x[0] x[1] x[2] ... x[N-1] h[0] h[1] h[2] ... h[M-1] and the output should be produced in the same order: y[0]...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT