0

Good Afternoon,

I apologize if this is a basic question, but I have been struggling with it, also still very new to Powershell.

I have a network mapped folder Z:\Test.

Under Z:\Test is multiple subfolders with the same structure. I need to loop through all of the subfolders and move all PDF files if they exist in a specific location.

Z:\Test\1\Work\PDF\*.PDF - then move Z:\Test\2\Work\PDF\*.PDF - Move So on and so on.

I have tried the following, but like I said I have been struggling with it. Thanks any help

Get-ChildItem -Path Z:\temp\*\Work -File -Include "*.PDF" -Recurse | Copy-Item -Force -Destination Y:\Temp\*\Work 
6
  • I formated your post to ease the readability a bit. Commented Jul 15, 2020 at 20:56
  • How to know which file should goes into which folder? I assume *.pdf means all pdf files, but how do you want to split them up, or should all PDF files go into the same folder? Commented Jul 15, 2020 at 21:00
  • If the file exists in the folder on the Z:\ then it needs to be copied to Y:\ for example Z:\1\Work\PDF\1.pdf That should copy to Y:\1\Work\PDF\ Commented Jul 15, 2020 at 21:02
  • Does this answer your question? Create directory if it does not exist Commented Jul 15, 2020 at 21:06
  • Also, I wrote an answer on this question which might help you. stackoverflow.com/questions/62797873/… Regarding your last comment, what problem do you actually get when trying to copy the files? Any errors? Commented Jul 15, 2020 at 21:07

1 Answer 1

0

I would try something like this:

$files = Get-ChildItem -Path Z:\Temp\*\Work -File -Include "*.PDF" -Recurse
foreach ($file in $files) {
    Copy-Item -Path $file.FullName -Destination Y:\Temp\*\Work -Force
}
Sign up to request clarification or add additional context in comments.

2 Comments

Ok, TY I will attempt your suggestion. Thanks again.
@JasonSteffens, in the loop you can filter the files in an if-statement for example.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.