Question

MUST USE PYTHON Write a program that recursively traverses a directory and prints out all file...

MUST USE PYTHON

Write a program that recursively traverses a directory and prints out all file names that start with a given string. For example, if user inputs (test_), then, the program should print all file names that start with test_. Note that directory names are excluded, in other words, if a directory is named test_1, then it should not be printed.

Input to program: prefix and directory where the program should start the search.

Note – you are not allowed to use os.walk().

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

import glob

#set the path of directory to search recursively

path = '../'

#enter string to start search the files who start with

fileName = input("Enter Filename to start with : ")

#get all the files recursively as list of files

files = [f for f in glob.glob(path + "**/*.*", recursive=True)]

#for each file name in files

for f in files:

#check if user entered string is in filename or not

if fileName in f:

print(f)

Add a comment
Know the answer?
Add Answer to:
MUST USE PYTHON Write a program that recursively traverses a directory and prints out all file...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT