Henry_Cornell Henry_Cornell - 3 months ago 12
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

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
    }