Anonymous user
Walk a directory/Recursively: Difference between revisions
no edit summary
m (→{{header|C#}}) |
No edit summary |
||
Line 618:
printf(fil, '%s\n');
endwhile;</lang>
=={{header|PowerShell}}==▼
In PowerShell the <code>Get-ChildItem</code> cmdlet allows for recursive filtering on file names with simple wildcards:▼
<lang powershell>Get-ChildItem -Recurse -Include *.mp3</lang>▼
For more complex filtering criteria the result of <code>Get-ChildItem</code> can be piped into the <code>Where-Object</code> cmdlet:▼
<lang powershell>Get-ChildItem -Recurse |▼
Where-Object { $_.Name -match 'foo[0-9]' -and $_.Length -gt 5MB }</lang>▼
To perform an action on every matching file the results can be piped into the <code>ForEach-Object</code> cmdlet:▼
<lang powershell>Get-ChildItem -Recurse |▼
Where-Object { $_.Name -match 'foo[0-9]' } |▼
ForEach-Object { ... }</lang>▼
''Note:'' To include only ''files'' instead of directories too each of the above needs an additional<code>Where-Object</code> filter:▼
<lang powershell>| Where-Object { !$_.PSIsContainer }</lang>▼
=={{header|Python}}==
Line 665 ⟶ 678:
for f in d.walkfiles(pattern):
print f</lang>
▲=={{header|PowerShell}}==
▲In PowerShell the <code>Get-ChildItem</code> cmdlet allows for recursive filtering on file names with simple wildcards:
▲<lang powershell>Get-ChildItem -Recurse -Include *.mp3</lang>
▲For more complex filtering criteria the result of <code>Get-ChildItem</code> can be piped into the <code>Where-Object</code> cmdlet:
▲<lang powershell>Get-ChildItem -Recurse |
▲ Where-Object { $_.Name -match 'foo[0-9]' -and $_.Length -gt 5MB }</lang>
▲To perform an action on every matching file the results can be piped into the <code>ForEach-Object</code> cmdlet:
▲<lang powershell>Get-ChildItem -Recurse |
▲ Where-Object { $_.Name -match 'foo[0-9]' } |
▲ ForEach-Object { ... }</lang>
▲''Note:'' To include only ''files'' instead of directories too each of the above needs an additional<code>Where-Object</code> filter:
▲<lang powershell>| Where-Object { !$_.PSIsContainer }</lang>
=={{header|R}}==
|