Delete all files from a folder and its sub folders

BobJim

I want to remove all files from a folder structure, so I'm left with an empty folder structure.

Can this be achieved in either batch or VBScript scripting?

I have tried a very basic batch command, but this required the user to allow the deletion of each file. This wasn't a suitable solution as there are many hundreds of files and this will increase massively over time.

What can you suggest?

MDMoore313

This can be accomplished using PowerShell:

Get-ChildItem -Path C:\Temp -Include *.* -File -Recurse | foreach { $_.Delete()}

This command gets each child item in $path, executes the delete method on each one, and is quite fast. The folder structure is left intact.

If you may have files without an extension, use

Get-ChildItem -Path C:\Temp -Include * -File -Recurse | foreach { $_.Delete()}

instead.

It appears the -File parameter may have been added after PowerShell v2. If that's the case, then

Get-ChildItem -Path C:\Temp -Include *.* -Recurse | foreach { $_.Delete()}

It should do the trick for files that have an extension.

If it does not work, check if you have an up-to-date version of Powershell

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to delete all the files in a folder including the files in the sub folders without deleting the the folder itself or any of its sub folders

From Dev

How to remove all empty files within folder and its sub folders?

From Dev

How to delete all files inside public_ftp folder—and its sub folders—which are older than X days using cron job?

From Dev

How to delete all files in particular folder present in current directory sub-folders excluding a certain file?

From Dev

Get Relative paths of all the folders, sub-folders and files in a folder

From Dev

Batch command to delete everything (sub folders and files) from a folder except one file

From Dev

How to give read write permission to a folder and its sub folders and files?

From Dev

How to give read write permission to a folder and its sub folders and files?

From Dev

Disable backup of documents folder and all its sub folders on icloud?

From Dev

How to delete all files/folders from a folder 'A' which are not present in the folder 'B', using Windows Batch Scripting?

From Dev

Extract files from a zip folder with sub folders into a single folder

From Dev

Move all files inside sub folders to parent folder

From Dev

Batch. Mass renaming files in the folder and all sub-folders

From Dev

Xampp htdocs folder, sub folders and all files permission

From Dev

Recursively search sub-folders and delete all files in sub-folders older than 6-months

From Dev

Recursively search sub-folders and delete all files in sub-folders older than 6-months

From Dev

Delete all files and folder except two folders using command prompt

From Dev

Delete all files and folders in a folder expect the ones ending with

From Dev

Recursively cleanup all folders and sub-folders in a folder that have no files in them

From Dev

Delete all zip files from a folder recursivley

From Dev

Find and delete all files without extensions witin a folder and its subfolders

From Dev

Find and delete all files without extensions witin a folder and its subfolders

From Dev

Find number of files in folder and sub folders?

From Dev

Java read files in folder and sub-folders

From Dev

Find number of files in folder and sub folders?

From Dev

Powershell: Move all files from folders and subfolders into single folder

From Dev

Copy all files and folders from one folder Batch

From Dev

Viewing all messages in sub folders in the containing folder?

From Dev

Command to delete all files from folders matching name recursivly?

Related Related

  1. 1

    How to delete all the files in a folder including the files in the sub folders without deleting the the folder itself or any of its sub folders

  2. 2

    How to remove all empty files within folder and its sub folders?

  3. 3

    How to delete all files inside public_ftp folder—and its sub folders—which are older than X days using cron job?

  4. 4

    How to delete all files in particular folder present in current directory sub-folders excluding a certain file?

  5. 5

    Get Relative paths of all the folders, sub-folders and files in a folder

  6. 6

    Batch command to delete everything (sub folders and files) from a folder except one file

  7. 7

    How to give read write permission to a folder and its sub folders and files?

  8. 8

    How to give read write permission to a folder and its sub folders and files?

  9. 9

    Disable backup of documents folder and all its sub folders on icloud?

  10. 10

    How to delete all files/folders from a folder 'A' which are not present in the folder 'B', using Windows Batch Scripting?

  11. 11

    Extract files from a zip folder with sub folders into a single folder

  12. 12

    Move all files inside sub folders to parent folder

  13. 13

    Batch. Mass renaming files in the folder and all sub-folders

  14. 14

    Xampp htdocs folder, sub folders and all files permission

  15. 15

    Recursively search sub-folders and delete all files in sub-folders older than 6-months

  16. 16

    Recursively search sub-folders and delete all files in sub-folders older than 6-months

  17. 17

    Delete all files and folder except two folders using command prompt

  18. 18

    Delete all files and folders in a folder expect the ones ending with

  19. 19

    Recursively cleanup all folders and sub-folders in a folder that have no files in them

  20. 20

    Delete all zip files from a folder recursivley

  21. 21

    Find and delete all files without extensions witin a folder and its subfolders

  22. 22

    Find and delete all files without extensions witin a folder and its subfolders

  23. 23

    Find number of files in folder and sub folders?

  24. 24

    Java read files in folder and sub-folders

  25. 25

    Find number of files in folder and sub folders?

  26. 26

    Powershell: Move all files from folders and subfolders into single folder

  27. 27

    Copy all files and folders from one folder Batch

  28. 28

    Viewing all messages in sub folders in the containing folder?

  29. 29

    Command to delete all files from folders matching name recursivly?

HotTag

Archive