I have a number of folders containing files with different extensions. I want to delete all files with an extension of .xyz but as there are so many occurrences, I don't want to do this manually. My scripting skills are next to zero. Can anyone lend me a hand at automating the process?
Thanks.
Script to delete files
-
- SilverLounger
- Posts: 1634
- Joined: 26 Jan 2010, 20:28
- Location: Ottawa ON
Script to delete files
Regards,
Paul
The correct term for gluten-free sugarless vegan brownies is 'compost'
Paul
-
- Microsoft MVP
- Posts: 1371
- Joined: 24 May 2013, 15:33
- Location: Warminster, PA
Re: Script to delete files
You don't really need scripting for this. A single command will do it.
Open a command window (it may be listed on your Start menu, or you can press Windows key + R to get the Run box and type cmd and press Enter).
If all the folders you want to work on are subfolders of one main folder, enter a CD command to go to that main folder. You can start at C:\ if you aren't sure.
Enter the command DEL /S *.xyz and press Enter. The /S switch says to look in all the subfolders of the current folder, and subfolders of those folders, all the way down.
If you want to be prompted for Yes or No for each file, include a /P switch before or after the /S switch.
If you'd prefer to see a list of the files that could be deleted, without actually deleting them yet, there's a way to do that in PowerShell.
Open a command window (it may be listed on your Start menu, or you can press Windows key + R to get the Run box and type cmd and press Enter).
If all the folders you want to work on are subfolders of one main folder, enter a CD command to go to that main folder. You can start at C:\ if you aren't sure.
Enter the command DEL /S *.xyz and press Enter. The /S switch says to look in all the subfolders of the current folder, and subfolders of those folders, all the way down.
If you want to be prompted for Yes or No for each file, include a /P switch before or after the /S switch.
If you'd prefer to see a list of the files that could be deleted, without actually deleting them yet, there's a way to do that in PowerShell.
-
- SilverLounger
- Posts: 1634
- Joined: 26 Jan 2010, 20:28
- Location: Ottawa ON
Re: Script to delete files
Thanks Jay. I didn't think it would be as simple as that. I'll give it a try.
If this becomes a regular thing, could I save this as a script to be used repetitively?
If this becomes a regular thing, could I save this as a script to be used repetitively?
Regards,
Paul
The correct term for gluten-free sugarless vegan brownies is 'compost'
Paul
-
- Microsoft MVP
- Posts: 1371
- Joined: 24 May 2013, 15:33
- Location: Warminster, PA
Re: Script to delete files
Yes, paste it into an empty text file and save it with a .bat extension -- that makes it a "batch file", which is executable just by double-clicking it.
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Script to delete files
Hi Paul,
Windows Explorer
A few other "non-script" options...
You can use Windows Explorer to do what you need. (IMHO, Win Explorer is actually very underrated!)
If you navigate to the highest directory in which the files are that you want to delete
Then in the search box, just type the *.xyz extension
This will list all of these file types from all sub directories in the directory you started at
Once the list of file types is displayed, you can select and delete them
See the screen shots below:
I navigated to SAMPLE FILES. You will see it lists multiple sub directories
Now in the search box (top right) I type out (for demo) the filter *.*
This lists ALL files in all the directories inside SAMPLE FILES
(Note: This step is not necessary - only for demo)
The next screen shot shows how I used the filter *.doc to extract all Word files.
Once the Word files from all the SAMPLE FILES sun folders are listed, I can simply select them and delete them (or copy them, or move them, etc)
Obviously in your case, you type the extension you need: Like the *.xyz as you referenced.
Windows Explorer
A few other "non-script" options...
You can use Windows Explorer to do what you need. (IMHO, Win Explorer is actually very underrated!)
If you navigate to the highest directory in which the files are that you want to delete
Then in the search box, just type the *.xyz extension
This will list all of these file types from all sub directories in the directory you started at
Once the list of file types is displayed, you can select and delete them
See the screen shots below:
I navigated to SAMPLE FILES. You will see it lists multiple sub directories
Now in the search box (top right) I type out (for demo) the filter *.*
This lists ALL files in all the directories inside SAMPLE FILES
(Note: This step is not necessary - only for demo)
The next screen shot shows how I used the filter *.doc to extract all Word files.
Once the Word files from all the SAMPLE FILES sun folders are listed, I can simply select them and delete them (or copy them, or move them, etc)
Obviously in your case, you type the extension you need: Like the *.xyz as you referenced.
You do not have the required permissions to view the files attached to this post.
Last edited by Rudi on 01 Dec 2015, 04:29, edited 1 time in total.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Script to delete files
File Bucket
Another useful third party app to do this type of thing is called File Bucket which is portable software, so no installation needed.
File Bucket is used to perform batch operations on a list of files that you browse to.
You can collect multiple files from different locations (hence the name "File Bucket") or you can navigate to a single main directory and run file operations on a list of files inside that folder (incl. the ability to filter for specific file types) as shown in the screen shot below...
I navigated to the same SAMPLE FILES location
Then added a "docx" filter (seen on the middle right of image)
And at the bottom I selected the operation to delete items to the Recycle Bin.
I have used this app many times to do some actions all at once on lists of files in completely different locations. A VERY handy tool.
Another useful third party app to do this type of thing is called File Bucket which is portable software, so no installation needed.
File Bucket is used to perform batch operations on a list of files that you browse to.
You can collect multiple files from different locations (hence the name "File Bucket") or you can navigate to a single main directory and run file operations on a list of files inside that folder (incl. the ability to filter for specific file types) as shown in the screen shot below...
I navigated to the same SAMPLE FILES location
Then added a "docx" filter (seen on the middle right of image)
And at the bottom I selected the operation to delete items to the Recycle Bin.
I have used this app many times to do some actions all at once on lists of files in completely different locations. A VERY handy tool.
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- SilverLounger
- Posts: 1634
- Joined: 26 Jan 2010, 20:28
- Location: Ottawa ON
Re: Script to delete files
Thanks, Jay. Just what I was looking for.Jay Freedman wrote:Yes, paste it into an empty text file and save it with a .bat extension -- that makes it a "batch file", which is executable just by double-clicking it.
Regards,
Paul
The correct term for gluten-free sugarless vegan brownies is 'compost'
Paul
-
- SilverLounger
- Posts: 1634
- Joined: 26 Jan 2010, 20:28
- Location: Ottawa ON
Re: Script to delete files
I nominate this statement for your Quote of the Week award! I certainly had not thought of Widows/File Explorer as a possible solution to this problem.Rudi wrote:IMHO, Win Explorer is actually very underrated!
Regards,
Paul
The correct term for gluten-free sugarless vegan brownies is 'compost'
Paul
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Script to delete files
Some people will completely refute that "quote" as they despise Win Explorer when compared to Command Line or with other 3rd party apps like File Commander, etc. However, it has a number of little gems and shortcuts that help to manage files on your system.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.