What should I use to accomplish the task desribed below?
- CMD.exe?
- PowerShell?
- Windows Script Host with VBScript or JScript?
Task:
- transverse into every sub-folder of a folder
- if the subfolder has a folder name XXX, invoke certain commands
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you decide to go PowerShell, which is what I would recommend, this task is pretty simple:
Short version using aliases is (note this version deletes the specified dirs from the current dir recursively):
This version shows you which dirs it would delete without actually deleting them. Remove the -wh (whatif) to have it actually delete the folders and tell you which ones it deleted. This is the “production” aspect of PowerShell. You can use -WhatIf (or -wh) on most cmdlets that are destructive to see what the command “would” do without actually performing the destructive operation. This is very handy when you want to kill processes based on a wildcard e.g.:
Another option is to use -Confirm and it will ask you for each process and you can tell it yes, no, yes to all, no to all. From the production point of view, I think PowerShell has a pretty clear advantage over some of the other options presented here. I’m just sayin’. 🙂