none
Clear-Content Powershell now working

    Question

  • Hi,

       I am new to Powershell.  I am referring to Clear-Content example mentioned in http://www.activexperts.com/network-monitor/windowsmanagement/powershell10/0026/ 

       I have a directory d:\data\lab.  Inside Lab different directories and subdirectories.  each directory and subdirectory contains *.txt file.  

    I want to write a powershell command which will empty content of all the txt files which are inside d:\data\lab

    I am using bellow command

     Clear-Content D:\data\Lab\* -Filter *.txt

    I tried so many permutation and combination, but its not removing content of text files which are inside d:\data\lab folder.

    Can anybody help?

    Thanks,

    Hemant Shelar

     


    Regards, Hemant Shelar

    • Moved by litdev Tuesday, August 28, 2012 5:32 PM (From:Small Basic)
    Tuesday, August 28, 2012 7:30 AM

Answers

  • Try:

    Get-Childitem -Path d:\data\lab -filter *.txt | Clear-Content


    Grant Ward, a.k.a. Bigteddy


    • Edited by Bigteddy Tuesday, August 28, 2012 5:45 PM
    • Proposed as answer by Knuckle-Dragger Wednesday, August 29, 2012 5:04 AM
    • Marked as answer by Hemant.Shelar Wednesday, August 29, 2012 5:12 AM
    Tuesday, August 28, 2012 5:45 PM
  • Hi,

       Thanks for your pointer.  Bellow command worked for me.  Bit modification to what you told.

    Get-ChildItem -Recurse -Path D:\data\Lab -Filter *.txt | Clear-Content

    Regards,

    Hemant Shelar


    Regards, Hemant Shelar

    • Marked as answer by Hemant.Shelar Wednesday, August 29, 2012 5:12 AM
    Wednesday, August 29, 2012 4:58 AM

All replies

  • Try:

    Get-Childitem -Path d:\data\lab -filter *.txt | Clear-Content


    Grant Ward, a.k.a. Bigteddy


    • Edited by Bigteddy Tuesday, August 28, 2012 5:45 PM
    • Proposed as answer by Knuckle-Dragger Wednesday, August 29, 2012 5:04 AM
    • Marked as answer by Hemant.Shelar Wednesday, August 29, 2012 5:12 AM
    Tuesday, August 28, 2012 5:45 PM
  • Hi,

       Thanks for your pointer.  Bellow command worked for me.  Bit modification to what you told.

    Get-ChildItem -Recurse -Path D:\data\Lab -Filter *.txt | Clear-Content

    Regards,

    Hemant Shelar


    Regards, Hemant Shelar

    • Marked as answer by Hemant.Shelar Wednesday, August 29, 2012 5:12 AM
    Wednesday, August 29, 2012 4:58 AM