Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Video Youtube
- https://youtu.be/QjC2wI0EQx8
- Codice Powershell
- ------------------------------------------------------------------------------
- $sourcePath = 'D:\Test'
- $inputFile = Join-Path -Path $sourcePath -ChildPath 'text.txt'
- # because the title may contain invalid characters for a folder name like ':'
- # create a regex to remove those if applicable
- $invalid = "[{0}]" -f [RegEx]::Escape(([IO.Path]::GetInvalidFileNameChars() -join ''))
- Import-Csv -Path $inputFile -Delimiter ';' -Header Title,FileName,Link | Group-Object Title | ForEach-Object {
- # combine the Title with the source path. Remove invalid characters from the Title
- $targetFolder = Join-Path -Path $sourcePath -ChildPath ($_.Name -replace $invalid)
- # if the destination folder does not already exist, create it
- if (!(Test-Path -Path $targetFolder -PathType Container)) {
- $null = New-Item -Path $targetFolder -ItemType Directory
- }
- foreach ($fileName in $_.Group.FileName) {
- $targetFile = Join-Path -Path $sourcePath -ChildPath $fileName
- if (Test-Path -Path $targetFile -PathType Leaf) {
- Move-Item -Path $targetFile -Destination $targetFolder -Force
- }
- else {
- Write-Warning "File '$targetFile' not found!"
- }
- }
- }
Add Comment
Please, Sign In to add comment