If you want to copy all *.txt files in folder C:\Source to C:\Destination preserving the directory structure:
Source files
C:\Source\Test1.cmd
C:\Source\Test1.txt
C:\Source\Dir1\Test2.txt
PowerShell statement
Copy-Item "C:\Source" "C:\Destination" -filter "*.txt" -recurse –force
Result (directory structure is preserved)
C:\Destination\Source\Test1.txt
C:\Destination\Source\Dir1\Test2.txt
If you want to copy all *.txt files in folder C:\Source to C:\Destination without preserving the directory structure:
Source files
C:\Source\Test1.cmd
C:\Source\Test1.txt
C:\Source\Dir1\Test2.txt
PowerShell statement
Get-ChildItem "C:\Source" -recurse -force -filter "*.txt" | Copy-Item -Destination "C:\Destination"
Result (directory structure is not preserved)
C:\Destination\Test1.txt
C:\Destination\Test2.txt
hi
really good instruction, just what i needed.
but there’s one problem.
i want to copy all “*.pst” from one drive (search all folders) to a share preserving the directory structure.
but your command copys all directorys from the drive, including empty ones.
can you help me?
greetings from switzerland