Delete all files from a folder and its sub folders The 2019 Stack Overflow Developer Survey...

Can a rogue use sneak attack with weapons that have the thrown property even if they are not thrown?

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

Which Sci-Fi work first showed weapon of galactic-scale mass destruction?

What is the meaning of the verb "bear" in this context?

Multiply Two Integer Polynomials

Is "plugging out" electronic devices an American expression?

How to check whether the reindex working or not in Magento?

Is a "Democratic" Oligarchy-Style System Possible?

If a Druid sees an animal’s corpse, can they Wild Shape into that animal?

Are there incongruent pythagorean triangles with the same perimeter and same area?

"as much details as you can remember"

Why not take a picture of a closer black hole?

Should I use my personal e-mail address, or my workplace one, when registering to external websites for work purposes?

Why can Shazam fly?

What does ひと匙 mean in this manga and has it been used colloquially?

Looking for Correct Greek Translation for Heraclitus

Is flight data recorder erased after every flight?

Have you ever entered Singapore using a different passport or name?

Landlord wants to switch my lease to a "Land contract" to "get back at the city"

Why isn't the circumferential light around the M87 black hole's event horizon symmetric?

Did Section 31 appear in Star Trek: The Next Generation?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

Why did Acorn's A3000 have red function keys?

Falsification in Math vs Science



Delete all files from a folder and its sub folders



The 2019 Stack Overflow Developer Survey Results Are InRecursively delete files that match file name (PowerShell script)Replacing files in a folder structure with files from an unsorted folderRobocopy: copy files preserving folder structure but adding a subfolderBatch delete temporary Windows files (system, browsers, cache, etc) for all usersBatch File:List all files of a type, rename files, flatten the directoryMoving files/folders to new structureMove all files from multiple subfolders into the parent folderAutomate the deletion of all files in a directory from a list of Windows computersHow to extract/convert hundreds of .mov files into PNG image files,automatically creating a folder for each group of PNG files extractedScript for deduplicating files and folders with a particular suffixBatch script to move files from parent folder into subfolders in lots of specified quantity





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







42















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?










share|improve this question

























  • You mean a recurssive delete? This can indeed be done. Something like rd /s /q "c:folder a will perform a recursive delete on all files and folders within Folder A

    – Ramhound
    Apr 15 '14 at 12:47













  • I could do, I dont know how to script in powershell but have previous run powershell scripts.

    – BobJim
    Apr 15 '14 at 13:41






  • 2





    Now is a perfect time to learn, I would research batch and vbs syntax for legacy purposes, but invest more time in learning PS.

    – MDMoore313
    Apr 15 '14 at 14:26











  • I havent had the chance to check the code yet although I'm sure it will work. I will come back and select the most appropiate answer to my initial query.

    – BobJim
    Apr 17 '14 at 7:08











  • I'll second @BigHomie's recommendation - I just learned some PowerShell and I'd have to say it's pretty neat - not too hard, a good weapon in any coder's arsenal. I use it fairly frequently now.

    – Ben
    Dec 19 '14 at 17:13


















42















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?










share|improve this question

























  • You mean a recurssive delete? This can indeed be done. Something like rd /s /q "c:folder a will perform a recursive delete on all files and folders within Folder A

    – Ramhound
    Apr 15 '14 at 12:47













  • I could do, I dont know how to script in powershell but have previous run powershell scripts.

    – BobJim
    Apr 15 '14 at 13:41






  • 2





    Now is a perfect time to learn, I would research batch and vbs syntax for legacy purposes, but invest more time in learning PS.

    – MDMoore313
    Apr 15 '14 at 14:26











  • I havent had the chance to check the code yet although I'm sure it will work. I will come back and select the most appropiate answer to my initial query.

    – BobJim
    Apr 17 '14 at 7:08











  • I'll second @BigHomie's recommendation - I just learned some PowerShell and I'd have to say it's pretty neat - not too hard, a good weapon in any coder's arsenal. I use it fairly frequently now.

    – Ben
    Dec 19 '14 at 17:13














42












42








42


12






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?










share|improve this question
















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?







windows script powershell batch-file vbscript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 7 '14 at 12:25









Peter Mortensen

8,396166185




8,396166185










asked Apr 15 '14 at 12:40









BobJimBobJim

4903821




4903821













  • You mean a recurssive delete? This can indeed be done. Something like rd /s /q "c:folder a will perform a recursive delete on all files and folders within Folder A

    – Ramhound
    Apr 15 '14 at 12:47













  • I could do, I dont know how to script in powershell but have previous run powershell scripts.

    – BobJim
    Apr 15 '14 at 13:41






  • 2





    Now is a perfect time to learn, I would research batch and vbs syntax for legacy purposes, but invest more time in learning PS.

    – MDMoore313
    Apr 15 '14 at 14:26











  • I havent had the chance to check the code yet although I'm sure it will work. I will come back and select the most appropiate answer to my initial query.

    – BobJim
    Apr 17 '14 at 7:08











  • I'll second @BigHomie's recommendation - I just learned some PowerShell and I'd have to say it's pretty neat - not too hard, a good weapon in any coder's arsenal. I use it fairly frequently now.

    – Ben
    Dec 19 '14 at 17:13



















  • You mean a recurssive delete? This can indeed be done. Something like rd /s /q "c:folder a will perform a recursive delete on all files and folders within Folder A

    – Ramhound
    Apr 15 '14 at 12:47













  • I could do, I dont know how to script in powershell but have previous run powershell scripts.

    – BobJim
    Apr 15 '14 at 13:41






  • 2





    Now is a perfect time to learn, I would research batch and vbs syntax for legacy purposes, but invest more time in learning PS.

    – MDMoore313
    Apr 15 '14 at 14:26











  • I havent had the chance to check the code yet although I'm sure it will work. I will come back and select the most appropiate answer to my initial query.

    – BobJim
    Apr 17 '14 at 7:08











  • I'll second @BigHomie's recommendation - I just learned some PowerShell and I'd have to say it's pretty neat - not too hard, a good weapon in any coder's arsenal. I use it fairly frequently now.

    – Ben
    Dec 19 '14 at 17:13

















You mean a recurssive delete? This can indeed be done. Something like rd /s /q "c:folder a will perform a recursive delete on all files and folders within Folder A

– Ramhound
Apr 15 '14 at 12:47







You mean a recurssive delete? This can indeed be done. Something like rd /s /q "c:folder a will perform a recursive delete on all files and folders within Folder A

– Ramhound
Apr 15 '14 at 12:47















I could do, I dont know how to script in powershell but have previous run powershell scripts.

– BobJim
Apr 15 '14 at 13:41





I could do, I dont know how to script in powershell but have previous run powershell scripts.

– BobJim
Apr 15 '14 at 13:41




2




2





Now is a perfect time to learn, I would research batch and vbs syntax for legacy purposes, but invest more time in learning PS.

– MDMoore313
Apr 15 '14 at 14:26





Now is a perfect time to learn, I would research batch and vbs syntax for legacy purposes, but invest more time in learning PS.

– MDMoore313
Apr 15 '14 at 14:26













I havent had the chance to check the code yet although I'm sure it will work. I will come back and select the most appropiate answer to my initial query.

– BobJim
Apr 17 '14 at 7:08





I havent had the chance to check the code yet although I'm sure it will work. I will come back and select the most appropiate answer to my initial query.

– BobJim
Apr 17 '14 at 7:08













I'll second @BigHomie's recommendation - I just learned some PowerShell and I'd have to say it's pretty neat - not too hard, a good weapon in any coder's arsenal. I use it fairly frequently now.

– Ben
Dec 19 '14 at 17:13





I'll second @BigHomie's recommendation - I just learned some PowerShell and I'd have to say it's pretty neat - not too hard, a good weapon in any coder's arsenal. I use it fairly frequently now.

– Ben
Dec 19 '14 at 17:13










12 Answers
12






active

oldest

votes


















64














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






share|improve this answer





















  • 1





    It's -Include *.* not -Include ., big difference! :-)

    – MDMoore313
    Apr 25 '14 at 11:00











  • Get-ChildItem -Path D:EmptyThisFolder -Include . -File -Recurse | foreach { $_.Delete()}

    – BobJim
    Apr 25 '14 at 13:07











  • Why are you using -Include . ?? That's what the problem is.

    – MDMoore313
    Apr 25 '14 at 13:08






  • 2





    Can't they implement powershell --version? Can't they use a version number with positive digits? It's just crazy. More than 1300 upvotes for a question on how to find out a version number of a program?

    – Thomas Weller
    Oct 6 '16 at 18:53






  • 1





    @demonicdaron its not supposed to; The OP's question was for preserving the folder structure.

    – MDMoore313
    Nov 29 '18 at 4:34



















21














You can do so with del command:



dir C:folder
del /S *


The /S switch is to delete only files recursively.






share|improve this answer



















  • 2





    Will this only delete files but leave the folders?

    – BobJim
    Apr 15 '14 at 12:56






  • 5





    Yes. You can add /P option so it will ask you to confirm every delete just to check that.

    – phoops
    Apr 15 '14 at 12:59













  • thanks ill give it a go! hopefully will save loads of time!

    – BobJim
    Apr 15 '14 at 13:11






  • 3





    Yes. And for deleting hidden and system files, do attrib -s -r -h Folder*.* /s /d before deleting. And for permissions use takeown command.

    – Jet
    Apr 25 '14 at 13:49








  • 2





    And you can use /Q to NOT ask for confirmation when using wildcards.

    – Aylatan
    Sep 25 '15 at 0:41





















12














Short and suite PowerShell. Not sure what the lowest version of PS it will work with.



Remove-Item c:Tmp* -Recurse -Force





share|improve this answer



















  • 1





    Nice and easy. This did the trick whilst the accepted answer did not!

    – demonicdaron
    Nov 28 '18 at 13:58



















4














Reading between the lines on your original question I can offer an alternative BATCH code line you can use. What this will do when ran is only delete files that are over 60 days old. This way you can put this in a scheduled task and when it runs it deletes the excess files that you don't need rather than blowing away the whole directory. You can change 60 to 5 days or even 1 day if you wanted to. This does not delete folders.



forfiles -p "c:pathtofiles" -d -60 -c "cmd /c del /f /q @path"





share|improve this answer


























  • Thanks for the idea but currently I think the "emptying" process will be completed on a very unscheduled adhoc time frame. I'll keep that code for the future though! Cheers

    – BobJim
    Apr 15 '14 at 13:42











  • The title reads "Delete all files from a folder and its sub folders" so this is not a solution.

    – Anders Lindén
    Aug 22 '17 at 6:26



















2














Using PowerShell:



Get-ChildItem -Path c:temp -Include * | remove-Item -recurse 





share|improve this answer

































    2














    Use PowerShell to Delete a Single File or Folder. Before executing the Delete command in powershell we need to make sure you are logged in to the server or PC with an account that has full access to the objects you want to delete.



    With Example: http://dotnet-helpers.com/powershell-demo/how-to-delete-a-folder-or-file-using-powershell/



    Using PowerShell commnads to delete a file




    Remove-Item -Path "C:dotnet-helpersDummyfiletoDelete.txt"




    The above command will execute and delete the “DummyfiletoDelete.txt” file which present inside the “C:dotnet-helpers” location.



    Using PowerShell commnads to delete all files




    Remove-Item -Path "C:dotnet-helpers*.*"




    Using PowerShell commnads to delete all files and folders




    Remove-Item -Path "C:dotnet-helpers*.*" -recurse




    -recurse drills down and finds lots more files. The –recurse parameter will allow PowerShell to remove any child items without asking for permission. Additionally, the –force parameter can be added to delete hidden or read-only files.



    Using -Force command to delete files forcefully



    Using PowerShell command to delete all files forcefully




    Remove-Item -Path "C:dotnet-helpers*.*" -Force







    share|improve this answer

































      1














      Try this using PowerShell. In this example I want to delete all the .class files:



      Get-ChildItem '.FOLDERNAME' -include *.class -recurse | foreach ($_) {remove-item $_.FullName}





      share|improve this answer

































        1















        1. In Windows Explorer select the root dir containing all the files and folders.


        2. Search for *


        3. Sort by Type (All the folders will be at the top and all the files listed underneath)


        4. Select all the files and press Delete.



        This will delete all the files and preserve the directory structure.






        share|improve this answer































          1














          Delete all files from current directory and sub-directories but leaving the folders structure.



          (/Q) switch is for asking the user if he is ok to delete



          Caution : try it without the /Q to make sure you are not deleting anything precious.



          del /S * /Q 





          share|improve this answer































            1














            This is the easiest way IMO



            Open PowerShell, navigate to the directory (cd), THEN



            ls -Recurse * | rm


            (Poof) everything is gone...



            If you want to delete based on a specific extension



            ls -Recurse *.docx | rm



            ls is listing the directory



            -Recurse is a flag telling powershell to go into any sub directories



            * says everything



            *.doc everything with .doc extension



            | feed the output from the left to the right



            rm delete




            All the other answers appear to make this more confusing than necessary.






            share|improve this answer

































              0














              dir C:testx -Recurse -File | rd -WhatIf
              What if: Performing the operation "Remove File" on target "C:testxx.txt".
              What if: Performing the operation "Remove File" on target "C:testxblax.txt".





              share|improve this answer

































                -1














                As a complement to the above answers, actually there's no need to use the Get-Childitem and pass the result to the pipeline in the above answers, because the -Include keyword is included in the Remove-Item command



                One can simply:



                Remove-Item -Include "." "C:Temp" -Recurse






                share|improve this answer
























                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "3"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f741945%2fdelete-all-files-from-a-folder-and-its-sub-folders%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  12 Answers
                  12






                  active

                  oldest

                  votes








                  12 Answers
                  12






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  64














                  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






                  share|improve this answer





















                  • 1





                    It's -Include *.* not -Include ., big difference! :-)

                    – MDMoore313
                    Apr 25 '14 at 11:00











                  • Get-ChildItem -Path D:EmptyThisFolder -Include . -File -Recurse | foreach { $_.Delete()}

                    – BobJim
                    Apr 25 '14 at 13:07











                  • Why are you using -Include . ?? That's what the problem is.

                    – MDMoore313
                    Apr 25 '14 at 13:08






                  • 2





                    Can't they implement powershell --version? Can't they use a version number with positive digits? It's just crazy. More than 1300 upvotes for a question on how to find out a version number of a program?

                    – Thomas Weller
                    Oct 6 '16 at 18:53






                  • 1





                    @demonicdaron its not supposed to; The OP's question was for preserving the folder structure.

                    – MDMoore313
                    Nov 29 '18 at 4:34
















                  64














                  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






                  share|improve this answer





















                  • 1





                    It's -Include *.* not -Include ., big difference! :-)

                    – MDMoore313
                    Apr 25 '14 at 11:00











                  • Get-ChildItem -Path D:EmptyThisFolder -Include . -File -Recurse | foreach { $_.Delete()}

                    – BobJim
                    Apr 25 '14 at 13:07











                  • Why are you using -Include . ?? That's what the problem is.

                    – MDMoore313
                    Apr 25 '14 at 13:08






                  • 2





                    Can't they implement powershell --version? Can't they use a version number with positive digits? It's just crazy. More than 1300 upvotes for a question on how to find out a version number of a program?

                    – Thomas Weller
                    Oct 6 '16 at 18:53






                  • 1





                    @demonicdaron its not supposed to; The OP's question was for preserving the folder structure.

                    – MDMoore313
                    Nov 29 '18 at 4:34














                  64












                  64








                  64







                  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






                  share|improve this answer















                  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







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 23 '17 at 11:33









                  Community

                  1




                  1










                  answered Apr 15 '14 at 13:18









                  MDMoore313MDMoore313

                  4,5192030




                  4,5192030








                  • 1





                    It's -Include *.* not -Include ., big difference! :-)

                    – MDMoore313
                    Apr 25 '14 at 11:00











                  • Get-ChildItem -Path D:EmptyThisFolder -Include . -File -Recurse | foreach { $_.Delete()}

                    – BobJim
                    Apr 25 '14 at 13:07











                  • Why are you using -Include . ?? That's what the problem is.

                    – MDMoore313
                    Apr 25 '14 at 13:08






                  • 2





                    Can't they implement powershell --version? Can't they use a version number with positive digits? It's just crazy. More than 1300 upvotes for a question on how to find out a version number of a program?

                    – Thomas Weller
                    Oct 6 '16 at 18:53






                  • 1





                    @demonicdaron its not supposed to; The OP's question was for preserving the folder structure.

                    – MDMoore313
                    Nov 29 '18 at 4:34














                  • 1





                    It's -Include *.* not -Include ., big difference! :-)

                    – MDMoore313
                    Apr 25 '14 at 11:00











                  • Get-ChildItem -Path D:EmptyThisFolder -Include . -File -Recurse | foreach { $_.Delete()}

                    – BobJim
                    Apr 25 '14 at 13:07











                  • Why are you using -Include . ?? That's what the problem is.

                    – MDMoore313
                    Apr 25 '14 at 13:08






                  • 2





                    Can't they implement powershell --version? Can't they use a version number with positive digits? It's just crazy. More than 1300 upvotes for a question on how to find out a version number of a program?

                    – Thomas Weller
                    Oct 6 '16 at 18:53






                  • 1





                    @demonicdaron its not supposed to; The OP's question was for preserving the folder structure.

                    – MDMoore313
                    Nov 29 '18 at 4:34








                  1




                  1





                  It's -Include *.* not -Include ., big difference! :-)

                  – MDMoore313
                  Apr 25 '14 at 11:00





                  It's -Include *.* not -Include ., big difference! :-)

                  – MDMoore313
                  Apr 25 '14 at 11:00













                  Get-ChildItem -Path D:EmptyThisFolder -Include . -File -Recurse | foreach { $_.Delete()}

                  – BobJim
                  Apr 25 '14 at 13:07





                  Get-ChildItem -Path D:EmptyThisFolder -Include . -File -Recurse | foreach { $_.Delete()}

                  – BobJim
                  Apr 25 '14 at 13:07













                  Why are you using -Include . ?? That's what the problem is.

                  – MDMoore313
                  Apr 25 '14 at 13:08





                  Why are you using -Include . ?? That's what the problem is.

                  – MDMoore313
                  Apr 25 '14 at 13:08




                  2




                  2





                  Can't they implement powershell --version? Can't they use a version number with positive digits? It's just crazy. More than 1300 upvotes for a question on how to find out a version number of a program?

                  – Thomas Weller
                  Oct 6 '16 at 18:53





                  Can't they implement powershell --version? Can't they use a version number with positive digits? It's just crazy. More than 1300 upvotes for a question on how to find out a version number of a program?

                  – Thomas Weller
                  Oct 6 '16 at 18:53




                  1




                  1





                  @demonicdaron its not supposed to; The OP's question was for preserving the folder structure.

                  – MDMoore313
                  Nov 29 '18 at 4:34





                  @demonicdaron its not supposed to; The OP's question was for preserving the folder structure.

                  – MDMoore313
                  Nov 29 '18 at 4:34













                  21














                  You can do so with del command:



                  dir C:folder
                  del /S *


                  The /S switch is to delete only files recursively.






                  share|improve this answer



















                  • 2





                    Will this only delete files but leave the folders?

                    – BobJim
                    Apr 15 '14 at 12:56






                  • 5





                    Yes. You can add /P option so it will ask you to confirm every delete just to check that.

                    – phoops
                    Apr 15 '14 at 12:59













                  • thanks ill give it a go! hopefully will save loads of time!

                    – BobJim
                    Apr 15 '14 at 13:11






                  • 3





                    Yes. And for deleting hidden and system files, do attrib -s -r -h Folder*.* /s /d before deleting. And for permissions use takeown command.

                    – Jet
                    Apr 25 '14 at 13:49








                  • 2





                    And you can use /Q to NOT ask for confirmation when using wildcards.

                    – Aylatan
                    Sep 25 '15 at 0:41


















                  21














                  You can do so with del command:



                  dir C:folder
                  del /S *


                  The /S switch is to delete only files recursively.






                  share|improve this answer



















                  • 2





                    Will this only delete files but leave the folders?

                    – BobJim
                    Apr 15 '14 at 12:56






                  • 5





                    Yes. You can add /P option so it will ask you to confirm every delete just to check that.

                    – phoops
                    Apr 15 '14 at 12:59













                  • thanks ill give it a go! hopefully will save loads of time!

                    – BobJim
                    Apr 15 '14 at 13:11






                  • 3





                    Yes. And for deleting hidden and system files, do attrib -s -r -h Folder*.* /s /d before deleting. And for permissions use takeown command.

                    – Jet
                    Apr 25 '14 at 13:49








                  • 2





                    And you can use /Q to NOT ask for confirmation when using wildcards.

                    – Aylatan
                    Sep 25 '15 at 0:41
















                  21












                  21








                  21







                  You can do so with del command:



                  dir C:folder
                  del /S *


                  The /S switch is to delete only files recursively.






                  share|improve this answer













                  You can do so with del command:



                  dir C:folder
                  del /S *


                  The /S switch is to delete only files recursively.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 15 '14 at 12:44









                  phoopsphoops

                  2,82731520




                  2,82731520








                  • 2





                    Will this only delete files but leave the folders?

                    – BobJim
                    Apr 15 '14 at 12:56






                  • 5





                    Yes. You can add /P option so it will ask you to confirm every delete just to check that.

                    – phoops
                    Apr 15 '14 at 12:59













                  • thanks ill give it a go! hopefully will save loads of time!

                    – BobJim
                    Apr 15 '14 at 13:11






                  • 3





                    Yes. And for deleting hidden and system files, do attrib -s -r -h Folder*.* /s /d before deleting. And for permissions use takeown command.

                    – Jet
                    Apr 25 '14 at 13:49








                  • 2





                    And you can use /Q to NOT ask for confirmation when using wildcards.

                    – Aylatan
                    Sep 25 '15 at 0:41
















                  • 2





                    Will this only delete files but leave the folders?

                    – BobJim
                    Apr 15 '14 at 12:56






                  • 5





                    Yes. You can add /P option so it will ask you to confirm every delete just to check that.

                    – phoops
                    Apr 15 '14 at 12:59













                  • thanks ill give it a go! hopefully will save loads of time!

                    – BobJim
                    Apr 15 '14 at 13:11






                  • 3





                    Yes. And for deleting hidden and system files, do attrib -s -r -h Folder*.* /s /d before deleting. And for permissions use takeown command.

                    – Jet
                    Apr 25 '14 at 13:49








                  • 2





                    And you can use /Q to NOT ask for confirmation when using wildcards.

                    – Aylatan
                    Sep 25 '15 at 0:41










                  2




                  2





                  Will this only delete files but leave the folders?

                  – BobJim
                  Apr 15 '14 at 12:56





                  Will this only delete files but leave the folders?

                  – BobJim
                  Apr 15 '14 at 12:56




                  5




                  5





                  Yes. You can add /P option so it will ask you to confirm every delete just to check that.

                  – phoops
                  Apr 15 '14 at 12:59







                  Yes. You can add /P option so it will ask you to confirm every delete just to check that.

                  – phoops
                  Apr 15 '14 at 12:59















                  thanks ill give it a go! hopefully will save loads of time!

                  – BobJim
                  Apr 15 '14 at 13:11





                  thanks ill give it a go! hopefully will save loads of time!

                  – BobJim
                  Apr 15 '14 at 13:11




                  3




                  3





                  Yes. And for deleting hidden and system files, do attrib -s -r -h Folder*.* /s /d before deleting. And for permissions use takeown command.

                  – Jet
                  Apr 25 '14 at 13:49







                  Yes. And for deleting hidden and system files, do attrib -s -r -h Folder*.* /s /d before deleting. And for permissions use takeown command.

                  – Jet
                  Apr 25 '14 at 13:49






                  2




                  2





                  And you can use /Q to NOT ask for confirmation when using wildcards.

                  – Aylatan
                  Sep 25 '15 at 0:41







                  And you can use /Q to NOT ask for confirmation when using wildcards.

                  – Aylatan
                  Sep 25 '15 at 0:41













                  12














                  Short and suite PowerShell. Not sure what the lowest version of PS it will work with.



                  Remove-Item c:Tmp* -Recurse -Force





                  share|improve this answer



















                  • 1





                    Nice and easy. This did the trick whilst the accepted answer did not!

                    – demonicdaron
                    Nov 28 '18 at 13:58
















                  12














                  Short and suite PowerShell. Not sure what the lowest version of PS it will work with.



                  Remove-Item c:Tmp* -Recurse -Force





                  share|improve this answer



















                  • 1





                    Nice and easy. This did the trick whilst the accepted answer did not!

                    – demonicdaron
                    Nov 28 '18 at 13:58














                  12












                  12








                  12







                  Short and suite PowerShell. Not sure what the lowest version of PS it will work with.



                  Remove-Item c:Tmp* -Recurse -Force





                  share|improve this answer













                  Short and suite PowerShell. Not sure what the lowest version of PS it will work with.



                  Remove-Item c:Tmp* -Recurse -Force






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 2 '17 at 17:21









                  Evan NadeauEvan Nadeau

                  12112




                  12112








                  • 1





                    Nice and easy. This did the trick whilst the accepted answer did not!

                    – demonicdaron
                    Nov 28 '18 at 13:58














                  • 1





                    Nice and easy. This did the trick whilst the accepted answer did not!

                    – demonicdaron
                    Nov 28 '18 at 13:58








                  1




                  1





                  Nice and easy. This did the trick whilst the accepted answer did not!

                  – demonicdaron
                  Nov 28 '18 at 13:58





                  Nice and easy. This did the trick whilst the accepted answer did not!

                  – demonicdaron
                  Nov 28 '18 at 13:58











                  4














                  Reading between the lines on your original question I can offer an alternative BATCH code line you can use. What this will do when ran is only delete files that are over 60 days old. This way you can put this in a scheduled task and when it runs it deletes the excess files that you don't need rather than blowing away the whole directory. You can change 60 to 5 days or even 1 day if you wanted to. This does not delete folders.



                  forfiles -p "c:pathtofiles" -d -60 -c "cmd /c del /f /q @path"





                  share|improve this answer


























                  • Thanks for the idea but currently I think the "emptying" process will be completed on a very unscheduled adhoc time frame. I'll keep that code for the future though! Cheers

                    – BobJim
                    Apr 15 '14 at 13:42











                  • The title reads "Delete all files from a folder and its sub folders" so this is not a solution.

                    – Anders Lindén
                    Aug 22 '17 at 6:26
















                  4














                  Reading between the lines on your original question I can offer an alternative BATCH code line you can use. What this will do when ran is only delete files that are over 60 days old. This way you can put this in a scheduled task and when it runs it deletes the excess files that you don't need rather than blowing away the whole directory. You can change 60 to 5 days or even 1 day if you wanted to. This does not delete folders.



                  forfiles -p "c:pathtofiles" -d -60 -c "cmd /c del /f /q @path"





                  share|improve this answer


























                  • Thanks for the idea but currently I think the "emptying" process will be completed on a very unscheduled adhoc time frame. I'll keep that code for the future though! Cheers

                    – BobJim
                    Apr 15 '14 at 13:42











                  • The title reads "Delete all files from a folder and its sub folders" so this is not a solution.

                    – Anders Lindén
                    Aug 22 '17 at 6:26














                  4












                  4








                  4







                  Reading between the lines on your original question I can offer an alternative BATCH code line you can use. What this will do when ran is only delete files that are over 60 days old. This way you can put this in a scheduled task and when it runs it deletes the excess files that you don't need rather than blowing away the whole directory. You can change 60 to 5 days or even 1 day if you wanted to. This does not delete folders.



                  forfiles -p "c:pathtofiles" -d -60 -c "cmd /c del /f /q @path"





                  share|improve this answer















                  Reading between the lines on your original question I can offer an alternative BATCH code line you can use. What this will do when ran is only delete files that are over 60 days old. This way you can put this in a scheduled task and when it runs it deletes the excess files that you don't need rather than blowing away the whole directory. You can change 60 to 5 days or even 1 day if you wanted to. This does not delete folders.



                  forfiles -p "c:pathtofiles" -d -60 -c "cmd /c del /f /q @path"






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 15 '14 at 17:21

























                  answered Apr 15 '14 at 13:18









                  TravisTravis

                  1,019716




                  1,019716













                  • Thanks for the idea but currently I think the "emptying" process will be completed on a very unscheduled adhoc time frame. I'll keep that code for the future though! Cheers

                    – BobJim
                    Apr 15 '14 at 13:42











                  • The title reads "Delete all files from a folder and its sub folders" so this is not a solution.

                    – Anders Lindén
                    Aug 22 '17 at 6:26



















                  • Thanks for the idea but currently I think the "emptying" process will be completed on a very unscheduled adhoc time frame. I'll keep that code for the future though! Cheers

                    – BobJim
                    Apr 15 '14 at 13:42











                  • The title reads "Delete all files from a folder and its sub folders" so this is not a solution.

                    – Anders Lindén
                    Aug 22 '17 at 6:26

















                  Thanks for the idea but currently I think the "emptying" process will be completed on a very unscheduled adhoc time frame. I'll keep that code for the future though! Cheers

                  – BobJim
                  Apr 15 '14 at 13:42





                  Thanks for the idea but currently I think the "emptying" process will be completed on a very unscheduled adhoc time frame. I'll keep that code for the future though! Cheers

                  – BobJim
                  Apr 15 '14 at 13:42













                  The title reads "Delete all files from a folder and its sub folders" so this is not a solution.

                  – Anders Lindén
                  Aug 22 '17 at 6:26





                  The title reads "Delete all files from a folder and its sub folders" so this is not a solution.

                  – Anders Lindén
                  Aug 22 '17 at 6:26











                  2














                  Using PowerShell:



                  Get-ChildItem -Path c:temp -Include * | remove-Item -recurse 





                  share|improve this answer






























                    2














                    Using PowerShell:



                    Get-ChildItem -Path c:temp -Include * | remove-Item -recurse 





                    share|improve this answer




























                      2












                      2








                      2







                      Using PowerShell:



                      Get-ChildItem -Path c:temp -Include * | remove-Item -recurse 





                      share|improve this answer















                      Using PowerShell:



                      Get-ChildItem -Path c:temp -Include * | remove-Item -recurse 






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Oct 28 '14 at 18:10









                      bwDraco

                      37.1k37138178




                      37.1k37138178










                      answered Oct 28 '14 at 15:39









                      Gregory SuvalianGregory Suvalian

                      1413




                      1413























                          2














                          Use PowerShell to Delete a Single File or Folder. Before executing the Delete command in powershell we need to make sure you are logged in to the server or PC with an account that has full access to the objects you want to delete.



                          With Example: http://dotnet-helpers.com/powershell-demo/how-to-delete-a-folder-or-file-using-powershell/



                          Using PowerShell commnads to delete a file




                          Remove-Item -Path "C:dotnet-helpersDummyfiletoDelete.txt"




                          The above command will execute and delete the “DummyfiletoDelete.txt” file which present inside the “C:dotnet-helpers” location.



                          Using PowerShell commnads to delete all files




                          Remove-Item -Path "C:dotnet-helpers*.*"




                          Using PowerShell commnads to delete all files and folders




                          Remove-Item -Path "C:dotnet-helpers*.*" -recurse




                          -recurse drills down and finds lots more files. The –recurse parameter will allow PowerShell to remove any child items without asking for permission. Additionally, the –force parameter can be added to delete hidden or read-only files.



                          Using -Force command to delete files forcefully



                          Using PowerShell command to delete all files forcefully




                          Remove-Item -Path "C:dotnet-helpers*.*" -Force







                          share|improve this answer






























                            2














                            Use PowerShell to Delete a Single File or Folder. Before executing the Delete command in powershell we need to make sure you are logged in to the server or PC with an account that has full access to the objects you want to delete.



                            With Example: http://dotnet-helpers.com/powershell-demo/how-to-delete-a-folder-or-file-using-powershell/



                            Using PowerShell commnads to delete a file




                            Remove-Item -Path "C:dotnet-helpersDummyfiletoDelete.txt"




                            The above command will execute and delete the “DummyfiletoDelete.txt” file which present inside the “C:dotnet-helpers” location.



                            Using PowerShell commnads to delete all files




                            Remove-Item -Path "C:dotnet-helpers*.*"




                            Using PowerShell commnads to delete all files and folders




                            Remove-Item -Path "C:dotnet-helpers*.*" -recurse




                            -recurse drills down and finds lots more files. The –recurse parameter will allow PowerShell to remove any child items without asking for permission. Additionally, the –force parameter can be added to delete hidden or read-only files.



                            Using -Force command to delete files forcefully



                            Using PowerShell command to delete all files forcefully




                            Remove-Item -Path "C:dotnet-helpers*.*" -Force







                            share|improve this answer




























                              2












                              2








                              2







                              Use PowerShell to Delete a Single File or Folder. Before executing the Delete command in powershell we need to make sure you are logged in to the server or PC with an account that has full access to the objects you want to delete.



                              With Example: http://dotnet-helpers.com/powershell-demo/how-to-delete-a-folder-or-file-using-powershell/



                              Using PowerShell commnads to delete a file




                              Remove-Item -Path "C:dotnet-helpersDummyfiletoDelete.txt"




                              The above command will execute and delete the “DummyfiletoDelete.txt” file which present inside the “C:dotnet-helpers” location.



                              Using PowerShell commnads to delete all files




                              Remove-Item -Path "C:dotnet-helpers*.*"




                              Using PowerShell commnads to delete all files and folders




                              Remove-Item -Path "C:dotnet-helpers*.*" -recurse




                              -recurse drills down and finds lots more files. The –recurse parameter will allow PowerShell to remove any child items without asking for permission. Additionally, the –force parameter can be added to delete hidden or read-only files.



                              Using -Force command to delete files forcefully



                              Using PowerShell command to delete all files forcefully




                              Remove-Item -Path "C:dotnet-helpers*.*" -Force







                              share|improve this answer















                              Use PowerShell to Delete a Single File or Folder. Before executing the Delete command in powershell we need to make sure you are logged in to the server or PC with an account that has full access to the objects you want to delete.



                              With Example: http://dotnet-helpers.com/powershell-demo/how-to-delete-a-folder-or-file-using-powershell/



                              Using PowerShell commnads to delete a file




                              Remove-Item -Path "C:dotnet-helpersDummyfiletoDelete.txt"




                              The above command will execute and delete the “DummyfiletoDelete.txt” file which present inside the “C:dotnet-helpers” location.



                              Using PowerShell commnads to delete all files




                              Remove-Item -Path "C:dotnet-helpers*.*"




                              Using PowerShell commnads to delete all files and folders




                              Remove-Item -Path "C:dotnet-helpers*.*" -recurse




                              -recurse drills down and finds lots more files. The –recurse parameter will allow PowerShell to remove any child items without asking for permission. Additionally, the –force parameter can be added to delete hidden or read-only files.



                              Using -Force command to delete files forcefully



                              Using PowerShell command to delete all files forcefully




                              Remove-Item -Path "C:dotnet-helpers*.*" -Force








                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited yesterday









                              Adil H. Raza

                              1034




                              1034










                              answered May 10 '18 at 7:13









                              thiyagu selvarajthiyagu selvaraj

                              211




                              211























                                  1














                                  Try this using PowerShell. In this example I want to delete all the .class files:



                                  Get-ChildItem '.FOLDERNAME' -include *.class -recurse | foreach ($_) {remove-item $_.FullName}





                                  share|improve this answer






























                                    1














                                    Try this using PowerShell. In this example I want to delete all the .class files:



                                    Get-ChildItem '.FOLDERNAME' -include *.class -recurse | foreach ($_) {remove-item $_.FullName}





                                    share|improve this answer




























                                      1












                                      1








                                      1







                                      Try this using PowerShell. In this example I want to delete all the .class files:



                                      Get-ChildItem '.FOLDERNAME' -include *.class -recurse | foreach ($_) {remove-item $_.FullName}





                                      share|improve this answer















                                      Try this using PowerShell. In this example I want to delete all the .class files:



                                      Get-ChildItem '.FOLDERNAME' -include *.class -recurse | foreach ($_) {remove-item $_.FullName}






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Dec 7 '14 at 12:29









                                      Peter Mortensen

                                      8,396166185




                                      8,396166185










                                      answered Nov 20 '14 at 21:28









                                      BoubakrBoubakr

                                      1112




                                      1112























                                          1















                                          1. In Windows Explorer select the root dir containing all the files and folders.


                                          2. Search for *


                                          3. Sort by Type (All the folders will be at the top and all the files listed underneath)


                                          4. Select all the files and press Delete.



                                          This will delete all the files and preserve the directory structure.






                                          share|improve this answer




























                                            1















                                            1. In Windows Explorer select the root dir containing all the files and folders.


                                            2. Search for *


                                            3. Sort by Type (All the folders will be at the top and all the files listed underneath)


                                            4. Select all the files and press Delete.



                                            This will delete all the files and preserve the directory structure.






                                            share|improve this answer


























                                              1












                                              1








                                              1








                                              1. In Windows Explorer select the root dir containing all the files and folders.


                                              2. Search for *


                                              3. Sort by Type (All the folders will be at the top and all the files listed underneath)


                                              4. Select all the files and press Delete.



                                              This will delete all the files and preserve the directory structure.






                                              share|improve this answer














                                              1. In Windows Explorer select the root dir containing all the files and folders.


                                              2. Search for *


                                              3. Sort by Type (All the folders will be at the top and all the files listed underneath)


                                              4. Select all the files and press Delete.



                                              This will delete all the files and preserve the directory structure.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Mar 16 '15 at 9:12









                                              EmelEmel

                                              111




                                              111























                                                  1














                                                  Delete all files from current directory and sub-directories but leaving the folders structure.



                                                  (/Q) switch is for asking the user if he is ok to delete



                                                  Caution : try it without the /Q to make sure you are not deleting anything precious.



                                                  del /S * /Q 





                                                  share|improve this answer




























                                                    1














                                                    Delete all files from current directory and sub-directories but leaving the folders structure.



                                                    (/Q) switch is for asking the user if he is ok to delete



                                                    Caution : try it without the /Q to make sure you are not deleting anything precious.



                                                    del /S * /Q 





                                                    share|improve this answer


























                                                      1












                                                      1








                                                      1







                                                      Delete all files from current directory and sub-directories but leaving the folders structure.



                                                      (/Q) switch is for asking the user if he is ok to delete



                                                      Caution : try it without the /Q to make sure you are not deleting anything precious.



                                                      del /S * /Q 





                                                      share|improve this answer













                                                      Delete all files from current directory and sub-directories but leaving the folders structure.



                                                      (/Q) switch is for asking the user if he is ok to delete



                                                      Caution : try it without the /Q to make sure you are not deleting anything precious.



                                                      del /S * /Q 






                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered May 18 '15 at 11:30









                                                      hdoghmenhdoghmen

                                                      1135




                                                      1135























                                                          1














                                                          This is the easiest way IMO



                                                          Open PowerShell, navigate to the directory (cd), THEN



                                                          ls -Recurse * | rm


                                                          (Poof) everything is gone...



                                                          If you want to delete based on a specific extension



                                                          ls -Recurse *.docx | rm



                                                          ls is listing the directory



                                                          -Recurse is a flag telling powershell to go into any sub directories



                                                          * says everything



                                                          *.doc everything with .doc extension



                                                          | feed the output from the left to the right



                                                          rm delete




                                                          All the other answers appear to make this more confusing than necessary.






                                                          share|improve this answer






























                                                            1














                                                            This is the easiest way IMO



                                                            Open PowerShell, navigate to the directory (cd), THEN



                                                            ls -Recurse * | rm


                                                            (Poof) everything is gone...



                                                            If you want to delete based on a specific extension



                                                            ls -Recurse *.docx | rm



                                                            ls is listing the directory



                                                            -Recurse is a flag telling powershell to go into any sub directories



                                                            * says everything



                                                            *.doc everything with .doc extension



                                                            | feed the output from the left to the right



                                                            rm delete




                                                            All the other answers appear to make this more confusing than necessary.






                                                            share|improve this answer




























                                                              1












                                                              1








                                                              1







                                                              This is the easiest way IMO



                                                              Open PowerShell, navigate to the directory (cd), THEN



                                                              ls -Recurse * | rm


                                                              (Poof) everything is gone...



                                                              If you want to delete based on a specific extension



                                                              ls -Recurse *.docx | rm



                                                              ls is listing the directory



                                                              -Recurse is a flag telling powershell to go into any sub directories



                                                              * says everything



                                                              *.doc everything with .doc extension



                                                              | feed the output from the left to the right



                                                              rm delete




                                                              All the other answers appear to make this more confusing than necessary.






                                                              share|improve this answer















                                                              This is the easiest way IMO



                                                              Open PowerShell, navigate to the directory (cd), THEN



                                                              ls -Recurse * | rm


                                                              (Poof) everything is gone...



                                                              If you want to delete based on a specific extension



                                                              ls -Recurse *.docx | rm



                                                              ls is listing the directory



                                                              -Recurse is a flag telling powershell to go into any sub directories



                                                              * says everything



                                                              *.doc everything with .doc extension



                                                              | feed the output from the left to the right



                                                              rm delete




                                                              All the other answers appear to make this more confusing than necessary.







                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Oct 12 '16 at 20:56

























                                                              answered Oct 12 '16 at 20:45









                                                              Kolob CanyonKolob Canyon

                                                              2471314




                                                              2471314























                                                                  0














                                                                  dir C:testx -Recurse -File | rd -WhatIf
                                                                  What if: Performing the operation "Remove File" on target "C:testxx.txt".
                                                                  What if: Performing the operation "Remove File" on target "C:testxblax.txt".





                                                                  share|improve this answer






























                                                                    0














                                                                    dir C:testx -Recurse -File | rd -WhatIf
                                                                    What if: Performing the operation "Remove File" on target "C:testxx.txt".
                                                                    What if: Performing the operation "Remove File" on target "C:testxblax.txt".





                                                                    share|improve this answer




























                                                                      0












                                                                      0








                                                                      0







                                                                      dir C:testx -Recurse -File | rd -WhatIf
                                                                      What if: Performing the operation "Remove File" on target "C:testxx.txt".
                                                                      What if: Performing the operation "Remove File" on target "C:testxblax.txt".





                                                                      share|improve this answer















                                                                      dir C:testx -Recurse -File | rd -WhatIf
                                                                      What if: Performing the operation "Remove File" on target "C:testxx.txt".
                                                                      What if: Performing the operation "Remove File" on target "C:testxblax.txt".






                                                                      share|improve this answer














                                                                      share|improve this answer



                                                                      share|improve this answer








                                                                      edited Apr 10 '17 at 10:59









                                                                      bertieb

                                                                      5,672112542




                                                                      5,672112542










                                                                      answered Apr 10 '17 at 10:36







                                                                      user646044






























                                                                          -1














                                                                          As a complement to the above answers, actually there's no need to use the Get-Childitem and pass the result to the pipeline in the above answers, because the -Include keyword is included in the Remove-Item command



                                                                          One can simply:



                                                                          Remove-Item -Include "." "C:Temp" -Recurse






                                                                          share|improve this answer




























                                                                            -1














                                                                            As a complement to the above answers, actually there's no need to use the Get-Childitem and pass the result to the pipeline in the above answers, because the -Include keyword is included in the Remove-Item command



                                                                            One can simply:



                                                                            Remove-Item -Include "." "C:Temp" -Recurse






                                                                            share|improve this answer


























                                                                              -1












                                                                              -1








                                                                              -1







                                                                              As a complement to the above answers, actually there's no need to use the Get-Childitem and pass the result to the pipeline in the above answers, because the -Include keyword is included in the Remove-Item command



                                                                              One can simply:



                                                                              Remove-Item -Include "." "C:Temp" -Recurse






                                                                              share|improve this answer













                                                                              As a complement to the above answers, actually there's no need to use the Get-Childitem and pass the result to the pipeline in the above answers, because the -Include keyword is included in the Remove-Item command



                                                                              One can simply:



                                                                              Remove-Item -Include "." "C:Temp" -Recurse







                                                                              share|improve this answer












                                                                              share|improve this answer



                                                                              share|improve this answer










                                                                              answered Oct 14 '18 at 14:59









                                                                              Sams0nTSams0nT

                                                                              11




                                                                              11






























                                                                                  draft saved

                                                                                  draft discarded




















































                                                                                  Thanks for contributing an answer to Super User!


                                                                                  • Please be sure to answer the question. Provide details and share your research!

                                                                                  But avoid



                                                                                  • Asking for help, clarification, or responding to other answers.

                                                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                                                  To learn more, see our tips on writing great answers.




                                                                                  draft saved


                                                                                  draft discarded














                                                                                  StackExchange.ready(
                                                                                  function () {
                                                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f741945%2fdelete-all-files-from-a-folder-and-its-sub-folders%23new-answer', 'question_page');
                                                                                  }
                                                                                  );

                                                                                  Post as a guest















                                                                                  Required, but never shown





















































                                                                                  Required, but never shown














                                                                                  Required, but never shown












                                                                                  Required, but never shown







                                                                                  Required, but never shown

































                                                                                  Required, but never shown














                                                                                  Required, but never shown












                                                                                  Required, but never shown







                                                                                  Required, but never shown







                                                                                  Popular posts from this blog

                                                                                  Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

                                                                                  VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

                                                                                  Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...