Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| powershell:qnd:file_operations [2022/05/12 23:26] – mgupton | powershell:qnd:file_operations [2022/10/06 20:13] (current) – mgupton | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| ~\Desktop | ~\Desktop | ||
| + | </ | ||
| + | |||
| + | === User Split-Path to get folder name === | ||
| + | <code powershell> | ||
| + | cd $(Split-Path $PROFILE) | ||
| </ | </ | ||
| ====== Common Commands By Example ====== | ====== Common Commands By Example ====== | ||
| - | === List Items with Filter === | + | === List Items with Filter/Search for files with matching string in name === |
| - | Example of finding a file somewhere in the filesystem. | + | Example of finding a file somewhere in the filesystem |
| + | <code powershell> | ||
| + | Get-ChildItem -Recurse -Filter " | ||
| + | </ | ||
| + | |||
| + | Use a regex with '' | ||
| <code powershell> | <code powershell> | ||
| - | Get-ChildItem | + | gci -Recurse |
| </ | </ | ||
| Line 85: | Line 95: | ||
| </ | </ | ||
| + | Unzip zip archives contained in another zip archive. | ||
| + | <code powershell> | ||
| + | Expand-Archive -DestinationPath .\zips ' | ||
| + | ls .\zips\ | % {Expand-Archive -DestinationPath $env:temp $_.FullName} | ||
| + | </ | ||
| + | === Create a folder with name following scheme === | ||
| + | <code powershell> | ||
| + | $suffix = 1 | ||
| + | |||
| + | while ((Test-Path " | ||
| + | $suffix += 1 | ||
| + | } | ||
| + | |||
| + | mkdir " | ||
| + | </ | ||
| + | |||
| + | <code powershell> | ||
| + | $names = @(" | ||
| + | |||
| + | $name = 0 | ||
| + | |||
| + | while ($name -lt $names.Count) { | ||
| + | if ((Test-Path " | ||
| + | break | ||
| + | } | ||
| + | |||
| + | $name += 1 | ||
| + | } | ||
| + | |||
| + | if ($name -eq $names.Count) { | ||
| + | $name = 0 | ||
| + | } | ||
| + | |||
| + | mkdir " | ||
| + | </ | ||