Last active
September 1, 2024 12:18
-
-
Save darallium/32c6cca1492f36f6cb9278ab2aef71d4 to your computer and use it in GitHub Desktop.
ファイルを整理するパワーシェルスクリプト ↑2行を良い感じに書き換えてください
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $sourceFolder = "D:\path\from\copy" | |
| $destinationFolder = "C:\path\to\extract" | |
| $files = Get-ChildItem -Path $sourceFolder -Recurse -File | |
| Write-Output "$files" | |
| foreach ($file in $files) { | |
| $Date = $file.CreationTime | |
| $year = $Date.Year | |
| $month = $Date.ToString("MM") | |
| $relativePath = $file.FullName.Substring($sourceFolder.Length).TrimStart("\\") | |
| $parentFolder = Split-Path -Parent $relativePath | |
| $targetFolder = Join-Path -Path $destinationFolder -ChildPath "$year\$month\$parentFolder" | |
| Write-Output "$year/$month/$File" | |
| if (-not (Test-Path -Path $targetFolder)) { | |
| New-Item -Path $targetFolder -ItemType Directory | Out-Null | |
| } | |
| $targetPath = Join-Path -Path $targetFolder -ChildPath $file.Name | |
| Copy-Item -Path $file.FullName -Destination $targetPath -Force | |
| } | |
| Write-Output "ファイルの分類とコピーが完了しました。" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $sourceFolder = "D:\path\from\copy" | |
| $destinationFolder = "C:\path\to\extract" | |
| $files = Get-ChildItem -Path $sourceFolder -Recurse -File | |
| Write-Output "$files" | |
| foreach ($file in $files) { | |
| $Date = $file.LastWriteTime | |
| $year = $Date.Year | |
| $month = $Date.ToString("MM") | |
| $relativePath = $file.FullName.Substring($sourceFolder.Length).TrimStart("\\") | |
| $parentFolder = Split-Path -Parent $relativePath | |
| $targetFolder = Join-Path -Path $destinationFolder -ChildPath "$year\$month\$parentFolder" | |
| Write-Output "$year/$month/$File" | |
| if (-not (Test-Path -Path $targetFolder)) { | |
| New-Item -Path $targetFolder -ItemType Directory | Out-Null | |
| } | |
| $targetPath = Join-Path -Path $targetFolder -ChildPath $file.Name | |
| Copy-Item -Path $file.FullName -Destination $targetPath -Force | |
| } | |
| Write-Output "ファイルの分類とコピーが完了しました。" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment