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...
a).Answer the question: where can you find the Standard Documentation for Python? b)Write an algorithm for...
a).Answer the question: where can you find the Standard Documentation for Python? b)Write an algorithm for step 3. c)Write a program that asks the user for a path to a directory, then updates the names of all the files in the directory that contain the word draft to instead say final      EX: "term paper (draft).txt" would be renamed "term paper (final).txt" BONUS (5pts): for any .txt file that your program changes the name of, have your program add a...
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...
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()
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...
[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]...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • The earth's magnetic field can affect the electron beam in an oscilloscope or a television tube....
    asked 8 minutes ago
  • The Huntington Boys and Girls Club is conducting a fundraiser by selling chili dinners to go....
    asked 17 minutes ago
  • 2. Please determinate the correctness of the following statements and justify your answers (preferably by examples)....
    asked 22 minutes ago
  • Explain the various methods of intelligence collection, specifically human intelligence and signals intelligence.
    asked 25 minutes ago
  • The provided file has syntax and/or logical errors. Determine the problem and fix the program. using...
    asked 28 minutes ago
  • What new items will you need to replace a failing processor? Select all that apply.   ...
    asked 47 minutes ago
  • A system is to be developed for an airport. When passengers have boarded an aircraft, a...
    asked 55 minutes ago
  • After reading Module 5 PowerPoint 1 - The Philosophy of Human Existance and Health Care Policy,...
    asked 1 hour ago
  • 1. Do you feel play has a place in supporting literacy development in early childhood? Explain...
    asked 1 hour ago
  • How should roles be selected for the Emergency Operations Center (EOC)?  Is seniority less important than experience?...
    asked 1 hour ago
  • Discuss routing issues and solutions namely, count-to-infinity, split horizon, split horizon with poison reverse, and hold-down...
    asked 1 hour ago
  • Find an optimal parenthesization of a matrix-chain product whose sequence of dimensions is〈5,10,3,12,5,50,6〉.
    asked 1 hour ago