Luis Diaz
asked on
Windows batch & Powershell: remove folders and exclude folders based on txt file
Hello experts,
I am looking for a procedure in order to remove folders located in a RootFolder
and exclude from the removal folders reported in a txt file.
Values to report in txt file: folder name and not folder path.
To keep in mind:
-Windows or Powershell approach are welcome
-Drill down mode not necessary
-RootFolder should be a variable to declare
-Log file to generate with folders removed
If you have questions, please contact me.
Thank you.
I am looking for a procedure in order to remove folders located in a RootFolder
and exclude from the removal folders reported in a txt file.
Values to report in txt file: folder name and not folder path.
To keep in mind:
-Windows or Powershell approach are welcome
-Drill down mode not necessary
-RootFolder should be a variable to declare
-Log file to generate with folders removed
If you have questions, please contact me.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
EXPERT CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tested and both procedures work!
@oBdA: I was wondering how you can send to next line if you have a long path folder in powershell:
Example :
$rootFolder = "C:\Temp\Root\toto\toto\toto”
$rootFolder = "C:\Temp\Root\” _
“toto\toto\toto”
Thank you in advance for your feedback.
In this case, just use a "+" - and watch out for your quotes! The two closing ones in lines 3 and 4 and the ones on the last line are not the ones PS expects in a script (" - ASCII 34), they're the 'purdy' typographical ones.
$rootFolder = "C:\Temp\Root\" +
"toto\toto\toto"
The backtick as last character on a line does that in PowerShell, but it won't work the same way as in VB(A/S). You need to build valid expressions, "string part1" "string part2" does not create a single string but two. In your example:
$rootFlder = "C:\Temp\Root\" +
"toto\toto\toto"
would work. PowerShell sees that there has to be something after the plus operator, and so will continue to look for stuff in the next line. But you can add a backtick to make sure things work as expected:$rootFlder = "C:\Temp\Root\" + `
"toto\toto\toto"
ASKER
Noted. Thank you.
ASKER