![]() The onliner copies the active-session-file from a folder to the root of the destination, instead of the its folder, plus it doesn't move the folder wher the file is in use. The onliner command doesn't work if the file(s) is open by some remote user(s) which is why I believe you might have developed this script. These one-liner people live in an ideal world with ideal problems, but you and I don't live in an ideal world. Regardless, I updated this with a cleaner implementation based off your judgmental, don't worry about people's comments. Sorry man I just got a little angry at that moment, I'm trying to make some batch script and at every little problem I stumble on complicated codes when most of them can be simply done, and about this problem to move all files and subfolders, people are doing foreach scripts using cmd mv function while it is possible to run powershell commands straight from batch file and do that operation with one line using move-item, and very few talk about it, plus there is on documentation no microsoft docs about calling powershell cmdlets straight from cmd. Regardless, I updated this with a cleaner implementation based off your judgmental suggestion There must have been some reason I did this in a convoluted way back in the day (perhaps there was a limitation in the Move-Item commandlet in older versions of Powershell) Moves all the contents including subfolders and files Move-item -path C:\SourceDir* -destination C:\Destination ![]() Remove-Item -Path "$($sourcePath)" -Recurse -Force -ErrorAction Stop Write-Host "Deleting folder '$($sourcePath)'" Write-Warning "Unable to move '$($file.FullName)' to '$(((Split-Path $file.FullName).Replace("$($sourcePath)",$destPath)))': $($_)" Move-Item -Path $file.FullName -Destination ((Split-Path $file.FullName).Replace("$($sourcePath)",$destPath)) -Force -ErrorAction Stop $directories = New-Item ($directory.FullName).Replace("$($sourcePath)",$destPath) -ItemType Directory -ea Silentlåontinue | Out-Null $directoryList = -Path "$($sourcePath)" -Directory -Recurse) $fileList = -Path "$($sourcePath)" -File -Recurse) ![]() Write-Host "Moving all files in '$($sourcePath)' to '$($destPath)'" Here is a "better" (different I would say) implementation to maintain the folders' structure:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |