Question

Selective Copy. Using Python program, write a program that walks through a folder tree and searches...

Selective Copy.

Using Python program, write a program that walks through a folder tree and searches for files with a certain file extension (such as .pdf or .jpg). Copy these files from whatever location they are in to a new folder.

Submit the code and a screenshot of the program running in Linux

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

CODE:

import os import shutil def selective_copy(input_folder, output_folder, ext): # getting absolute path of input folder not relative path input_folder = os.path.abspath(input_folder) # getting absolute path of output folder not relative path output_folder = os.path.abspath(output_folder) # printing message to show user print("The Program is Looking for", ', '.join(ext), "in", input_folder) # traverse all contents of the input_folder directory for folder, subfolders, files in os.walk(input_folder): for file in files: # splitting with name and extension name, extension = os.path.splitext(file) if extension in ext: file_Absolute_Path = folder + os.path.sep + file # copying files shutil.copy(file_Absolute_Path, output_folder) print("Copying....") if __name__=='__main__': input_folder = 'HomeworkLib' output_folder = 'hello' ext = ['.py', '.jpg'] # create directory os.mkdir(output_folder) selective_copy(input_folder, output_folder, ext) ''' OUTPUT: The Program is Looking for .pdf, .jpg in E:\Softwares\python\PycharmProjects\test\HomeworkLib Copying.... Copying.... Copying.... Copying.... '''

OUTPUT:

Please upvote if you like my answer and comment below if you have any queries.

Add a comment
Know the answer?
Add Answer to:
Selective Copy. Using Python program, write a program that walks through a folder tree and searches...
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
  • using python, Write a function named displayReverse that takes a list as a parameter and DISPLAYS...

    using python, Write a function named displayReverse that takes a list as a parameter and DISPLAYS the contents of the list to the screen in reverse. Submit the code and a screenshot of the program running in Linux

  • Write a python function named displayFizzBuzz that takes a number as a parameter and DISPLAYS the...

    Write a python function named displayFizzBuzz that takes a number as a parameter and DISPLAYS the appropriate FizzBuzz value for that number. Test this function on all of the numbers between 1 and 100000. Submit the code and a screenshot of the program running in Linux

  • Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a...

    Write a python program and pseudocode The Program Using Windows Notepad (or similar program), create a file called Numbers.txt in your the same folder as your Python program. This file should contain a list on floating point numbers, one on each line. The number should be greater than zero but less than one million. Your program should read the following and display: The number of numbers in the file (i.e. count them) (counter) The maximum number in the file (maximum)...

  • Challenge: Recursion and Python Turtle Graphics Submit Assignment Due Friday by 11:59pm Points 100 Submitting a...

    Challenge: Recursion and Python Turtle Graphics Submit Assignment Due Friday by 11:59pm Points 100 Submitting a file upload Available after Nov 9 at 12am Challenge: Recursion and Python Turtle Graphics Description: Write a program that draws a picture using Python e, recursion, and Turtle graphics e. Purpose: The purpose of this challenge is to provide experience working with recursione in Pythone. It also provides experience working with Turtle graphics in Pythone Requirements: Recursion and Python Turtle Graphics provides information on...

  • Problem 4: (7 pts) To understand the value of recursion in a programming language, write a...

    Problem 4: (7 pts) To understand the value of recursion in a programming language, write a Program in C++ or Python that implements quicksort, first using recursion and then without recursion. Submit your program source code and  screenshot(s) of the output in a separate file (pdf or .docx) Problem 5: (7 pts) To understand the value of counting loops, write a program in C++ or Python that implements matrix multiplication using counting loop constructs. Let the user input the size/dimensions of...

  • Write a Python equivalent program for the Unix spell utility. You can use the dictionary at /usr/...

    Write a Python equivalent program for the Unix spell utility. You can use the dictionary at /usr/share/dict/words (if you machine does not have it, you can copy it from a Linux machine such as npu29). The minimum requirement is to check if each word in the file exists in the dictionary as is (case insensitive). Your spell checker should inlcude at least two features: 1. Check the simple plural forms (add s or es). 2. Check the simple verb past...

  • IN PYTHON USING IDLE PLATFORM PLEASE ALSO POST CODE TO COPY PLEASE Write a PYTHON Program...

    IN PYTHON USING IDLE PLATFORM PLEASE ALSO POST CODE TO COPY PLEASE Write a PYTHON Program that will ask the user for a base number then the program should display the multiplication table of that number up to 12.

  • Question 1 In the following incomplete C program: #include stdlib.h> #include <stdio.h> int main () { int i, n, max; int array[100]; ... } return 0; } an array of random int values is populat...

    Question 1 In the following incomplete C program: #include stdlib.h> #include <stdio.h> int main () { int i, n, max; int array[100]; ... } return 0; } an array of random int values is populated with n random values. Write only the code to find the location of the maximum value in the array. Question 2 Follow these instructions in your Linux account: 1. Create a file called data.txt in the root folder in your account. 2. Create a new...

  • Comma Code (Using Python Language) Say you have a list value like this: spam = [...

    Comma Code (Using Python Language) Say you have a list value like this: spam = [ 'apples' , 'bananas' , 'tofu', 'cats' ] Write a function that takes a list value as an argument and returns a string will all the items separated by comma and space, with and inserted before the last item. For example, passing the previous spam list to the function would return 'apples, bananas, tofu and cats'. but your function should be able to work with...

  • Exercise 1: Create a file by using any word processing program or text editor. Write an...

    Exercise 1: Create a file by using any word processing program or text editor. Write an application that displays the file's name, size, and time of last modification. Save the file as FileStatistics.java. Exercise 2: Create a file that contains your favorite movie quote. Use a text editor, such as Notepad, and save the file as Quote.txt. Copy the file contents and paste them into a word processing program, such as Word. Save the file as Quote.doc. Write an application...

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