2012-08-03 20 views
9

Ciao Mi piacerebbe creare un file batch per ottenere tutte le sotto-cartelle. Qualcuno, per favore aiutami su questo?loop through sottocartelle

+2

rendere la vostra mente ... vuoi un file batch o uno script PowerShell? – Joey

risposta

9

Questo è banale in entrambi i file batch o PowerShell:

lotto:

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

PowerShell:

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

Ciao @ Joey, esiste un metodo che utilizza sqlcmd per scorrere tutte le sottocartelle senza codificare il percorso delle sottocartelle? e per lo script PowerShell l'ultima riga, potresti fornire un esempio per questo "sqlcmd $ _ # o qualsiasi altra cosa"? grazie mille –

1

Ecco uno script PowerShell che uso per ottenere la dimensione del " Scuola "all'interno della sottocartella delle cartelle home di ciascun utente. IE. N: \ nomeutente \ UserNameOSXProfile \ Scuola

SizeOfSchoolFolder.ps1

$schoolFolderTotalSize=0 

$foundChildren = get-childitem *\*OSXProfile\School 
foreach($file in $foundChildren){ 
    $schoolFolderTotalSize = $schoolFolderTotalSize + [long](ls -r $file.FullName | measure -s Length).Sum 
} 

switch($schoolFolderTotalSize) { 
    {$_ -gt 1GB} { 
    '{0:0.0} GiB' -f ($_/1GB) 
    break 
    } 
    {$_ -gt 1MB} { 
    '{0:0.0} MiB' -f ($_/1MB) 
    break 
    } 
    {$_ -gt 1KB} { 
    '{0:0.0} KiB' -f ($_/1KB) 
    break 
    } 
    default { "$_ bytes" } 
} 

ho tirato i numeri aggiungendo da: Adding up numbers in PowerShell

E la dimensione della cartella facendo apparire bella: Get Folder Size from Windows Command Line

E \ * \ * OSXProfile \ School come ricerca per una sottocartella specifica. Limit Get-ChildItem recursion depth

0

di sostituire 'xyz' con 'abc' in tutti i nomi di file:

Get-ChildItem -Recurse -Filter *.mp3 | Rename-Item –NewName { $_.name –replace 'xyz','abc' }