This script works perfectly in PowerShell. It copies all files with specific type. But I want copy files with it folders & subfolders.
$dest = "C:\example" $files = Get-ChildItem -Path "C:\example" -Filter "*.msg" -Recurse foreach ($file in $files) { $file_path = Join-Path -Path $dest -ChildPath $file.Name $i = 1 while (Test-Path -Path $file_path) { $i++ $file_path = Join-Path -Path $dest -ChildPath "$($file.BaseName)_$($i)$($file.Extension)" } Copy-Item -Path $file.FullName -Destination $file_path }
Type "xcopy", "source", "destination" /t /e in the Command Prompt window. Instead of “ source ,” type the path of the folder hierarchy you want to copy. Instead of “ destination ,” enter the path where you want to store the copied folder structure. Press “Enter” on your keyboard.
If you want to copy the set of files to multiple folders, hold down the CONTROL key while dragging and dropping the file(s). This ensures that the files in the drop stack are not removed once the copy process has completed. This makes it easy to copy the same set of files (from different folders) to multiple locations.
Alternatively, right-click the folder, select Show more options and then Copy. In Windows 10 and earlier versions, right-click the folder and select Copy, or click Edit and then Copy. Navigate to the location where you want to place the folder and all its contents.
If you have the Google Drive app installed on your computer, you can copy a folder in Google Drive the same way you'd copy any other folder of files. Right-click on the folder, click Copy, then go wherever you want to copy the folder, right-click again, and click Paste.
Source: https://blogs.technet.microsoft.com/heyscriptingguy/2013/07/04/powertip-use-powershell-to-copy-items-and-retain-folder-structure/
Question: How can I use Windows PowerShell 3.0 to copy a folder structure from a drive to a network share, and retain the original structure?
Answer: Use the Copy-Item
cmdlet and specify the –Container
switched parameter:
$sourceRoot = "C:\temp" $destinationRoot = "C:\n" Copy-Item -Path $sourceRoot -Filter "*.txt" -Recurse -Destination $destinationRoot -Container
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With