Henry_Cornell Henry_Cornell - 1 year ago 70
PowerShell Question

loop through subfolders

Hi I would like to create a batch file to get all the sub-folders.Can anyone please help me on this?

Answer Source

This is trivial in both batch files or PowerShell:

Batch:

for /r %%x in (*.sql) do (
    rem "(or whatever)"
    sqlcmd "%%x"
)

PowerShell:

Get-ChildItem -Recurse -Filter *.sql |
    ForEach-Object {
        sqlcmd $_.FullName # or whatever
    }