none
Guru's - Need help on script RRS feed

  • Question

  • Scripting guru's - need help

    I got a text file, which got path to multiple files like:

    D:\testfolder\testfolder1\testfolder1file.txt
    D:\testfolder\testfolder2\testfolder2file.txt

    I need help with a script which will read the content of input - text file (this will contain the file extension and the path of the file), check the existence of the file and delete the file (only) leaving folder at the path.

    Thanks



    Inderjit

    Thursday, June 11, 2015 10:34 AM

Answers

  • Hello,

    If I understand your goal, it is very simple to do so in PowerShell :

    # We are getting the content of a text file
    $files = Get-Content -path "your_input_text_file"
    
    # We are removing the files specified in the $files variable
    # Remove the -whatIf switch when you are sure you want to delete the files
    $files | Remove-Item -WhatIf

    The -WhatIf switch used here allows you to simulate the result of the script, so to check which files are going to be deleted. Simply remove this switch when you are sure you want to delete them. 


    • Proposed as answer by Antoine Delrue Thursday, June 11, 2015 11:35 AM
    • Edited by Antoine Delrue Thursday, June 11, 2015 11:36 AM
    • Marked as answer by IJSingh Thursday, June 11, 2015 3:34 PM
    Thursday, June 11, 2015 11:35 AM

All replies

  • Hello,

    If I understand your goal, it is very simple to do so in PowerShell :

    # We are getting the content of a text file
    $files = Get-Content -path "your_input_text_file"
    
    # We are removing the files specified in the $files variable
    # Remove the -whatIf switch when you are sure you want to delete the files
    $files | Remove-Item -WhatIf

    The -WhatIf switch used here allows you to simulate the result of the script, so to check which files are going to be deleted. Simply remove this switch when you are sure you want to delete them. 


    • Proposed as answer by Antoine Delrue Thursday, June 11, 2015 11:35 AM
    • Edited by Antoine Delrue Thursday, June 11, 2015 11:36 AM
    • Marked as answer by IJSingh Thursday, June 11, 2015 3:34 PM
    Thursday, June 11, 2015 11:35 AM
  • That was easy, thanks

    sometime you need only the basics


    Inderjit

    Thursday, June 11, 2015 12:01 PM
  • That was easy, thanks

    sometime you need only the basics


    Inderjit

    Glad it helped, please mark my answer as accepted, and upvote it, this will help for future researches. 

    Thanks in advance.

    Thursday, June 11, 2015 12:18 PM