Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Video youtube:
- youtu.be/3SF20MpsJdY
- --------------------------
- $SourcePath = 'C:\xxx\1'
- $TargetPath = 'C:\xxx\2'
- $FolderList = Get-ChildItem -Path $SourcePath -Filter "*volume*" -Directory
- foreach ($Folder in $FolderList) {
- $Name1 = ($Folder.Name -split '-')[0].Trim()
- $TargetFolder = Join-Path -Path $TargetPath -ChildPath $Name1
- if (-not (Test-Path -Path $TargetFolder)) {
- New-Item -Path $TargetFolder -ItemType Directory | Out-Null
- }
- Move-Item -Path $Folder.FullName -Destination $TargetFolder
- }
- ***************************************
- VERSIONE ALTERNATIVA :: usare la versione 7 di Powershell !!
- ***************************************
- I see that you have selected an answer. Here is another way.
- # Setup test data
- $Dirs = @(
- 'Absolute Moebius - Volume 2 - The Long Tomorrow'
- ,'Absolute Moebius - Volume 3'
- ,'Agenzia X - Volume 1 - La Recluta'
- ,'Agenzia X - Volume 2 - Black Point'
- ,'Agenzia X - Volume 3 - Soli'
- ,'Akira - Volume 10'
- ,'Akira - Volume 20'
- ,'Akira - Volume 23'
- ,'Alan Ford - Volume 11 - Il Numero Uno'
- ,'Alan Ford - Volume 12 - La Triste Storia Di Un Giovane Ricco'
- ,'Alan Ford - Volume 13 - Golf'
- )
- foreach ($Dir in $Dirs) {
- if (-not (Test-Path -Path $Dir)) { New-Item -ItemType Directory -Path $Dir | Out-Null }
- }
- # Code to move files starts here vvvvvvvvvvvvvvvvvvvv
- (Get-ChildItem -Directory -Filter '* - Volume*').Name |
- ForEach-Object {
- $NewDirName = $_.Split(' - ')[0]
- if (-not (Test-Path -Path $NewDirName)) { New-Item -ItemType Directory -Path $NewDirName | Out-Null }
- Move-Item -Path $_ -Destination $NewDirName
- }
- # Code to move files ends here ^^^^^^^^^^^^^^^^^^^
Add Comment
Please, Sign In to add comment