delete specific files with extention in bulk with user input

user15106706

I need to delete files with a specific extension but IT HAS TO TAKE THE USERS INPUT and the script I have does that but it does it one by one but not in bulk and I have honestly been very confused on how to complete this can I get some help on this please I have been struggling, the script below I appreciate all help:

for root, dirnames, filenames in os.walk('path'):
    for xml in filenames:
        if xml.lower().endswith('.xml'):
            if input('remove exisiting xml files? y/n: ') == "y":
                os.remove(os.path.join(root, XML))
                print('the file has been deleted succesfully')
    else:
        print('the file has not been deleted')
Marcos

Why not asking first the input question once for all the files, and then deleting every file after confirmation? For example:

import os

if input('remove exisiting xml files? y/n: ') != "y":
    print('Canceling deleting process')
else:
    print('deleting all xml files')
    for root, dirnames, filenames in os.walk('path'):
        for xml in filenames:
            if xml.lower().endswith('.xml'):
                file_path = os.path.join(root, xml)
                print(f'deleting file {file_path}')
                os.remove(file_path)

  

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Bat script to delete files with specific extention

From Dev

Lua function to delete files with specific extention or pattern

From Dev

XML with links & VB search & delete files extention

From Dev

Allow user via FTP to edit, delete & create files in specific folder

From Dev

Changing files' extention in loop

From Dev

how do i search for specific files by user input

From Dev

Overwriting specific Line in multiple Files using PowerShell with User Input

From Dev

Delete specific files in directory

From Dev

Locate a specific line in a file based on user input then delete a specific number of lines

From Dev

How to search for files with a specific extention from a specifically given directory and all subdirectories

From Dev

How to delete a specific line in a text file using user input Python 3

From Dev

delete user specific content in django

From Dev

Delete a specific user from Firebase

From Dev

delete specific files and retain some

From Dev

Loop to Delete Specific Files in Matlab

From Dev

Delete files/uploads when delete User

From Dev

Printing specific user input in java

From Dev

R: Specific user input to dataframe

From Dev

Delete a user and all files owned by this user

From Dev

Delete a user and all files owned by this user

From Dev

renaming video files in bulk taking input from a playlist file

From Dev

Chrome Extention Only Available in Specific Website

From Dev

Add additional extention to specific file in bash

From Dev

PowerShell & Batch Files With User Input

From Dev

Php list files in a directory and remove extention

From Dev

Delete User Input from the Terminal in C

From Dev

How to delete the key of the object based on user input?

From Dev

Delete all files except filenames with specific string

From Dev

Delete files older than specific file

Related Related

  1. 1

    Bat script to delete files with specific extention

  2. 2

    Lua function to delete files with specific extention or pattern

  3. 3

    XML with links & VB search & delete files extention

  4. 4

    Allow user via FTP to edit, delete & create files in specific folder

  5. 5

    Changing files' extention in loop

  6. 6

    how do i search for specific files by user input

  7. 7

    Overwriting specific Line in multiple Files using PowerShell with User Input

  8. 8

    Delete specific files in directory

  9. 9

    Locate a specific line in a file based on user input then delete a specific number of lines

  10. 10

    How to search for files with a specific extention from a specifically given directory and all subdirectories

  11. 11

    How to delete a specific line in a text file using user input Python 3

  12. 12

    delete user specific content in django

  13. 13

    Delete a specific user from Firebase

  14. 14

    delete specific files and retain some

  15. 15

    Loop to Delete Specific Files in Matlab

  16. 16

    Delete files/uploads when delete User

  17. 17

    Printing specific user input in java

  18. 18

    R: Specific user input to dataframe

  19. 19

    Delete a user and all files owned by this user

  20. 20

    Delete a user and all files owned by this user

  21. 21

    renaming video files in bulk taking input from a playlist file

  22. 22

    Chrome Extention Only Available in Specific Website

  23. 23

    Add additional extention to specific file in bash

  24. 24

    PowerShell & Batch Files With User Input

  25. 25

    Php list files in a directory and remove extention

  26. 26

    Delete User Input from the Terminal in C

  27. 27

    How to delete the key of the object based on user input?

  28. 28

    Delete all files except filenames with specific string

  29. 29

    Delete files older than specific file

HotTag

Archive