<p style=“text-align: right;”>Hi, I am a newbie to powershell.My requirement is copying last modified file to destination folder.The files and subfolder name also need to copied.</p>
<p style=“text-align: right;”>Let me explain clearly by structure.</p>
<p style=“text-align: right;”>Source</p>
<p style=“text-align: right;”>Subfolder:1</p>
<p style=“text-align: right;”>Text1.</p>
<p style=“text-align: right;”>Text2(last modified)</p>
<p style=“text-align: right;”>Subfolder 2</p>
<p style=“text-align: right;”>Text3</p>
<p style=“text-align: right;”>Text4(last modified)</p>
<p style=“text-align: right;”>Subfolder</p>
<p style=“text-align: right;”>Text5</p>
<p style=“text-align: right;”>Text6</p>
Output:This is what I need
OK, you did not specify the desired age in your first post.
With this requirement you will have to extract the part of the source path you want to mirror in the target, create the target folder first before you’re able to copy the file to the newly created desitnation folder.
There are several examples throughout the internet for Powershell scripts with this kind of requirements. You should search for it in the PowershellGallery or StackOverflow or in the Microsoft Technet Forums. You don’t have to re-invent the wheel.
If you like to do it by yourself anyway … the following example illustrates how to extract the target folder structure: