Reputation: 49
Copy-Item -Path \\User\LS\ADMIN\HW\DATA\Payroll\20200120\FWES_0D526B00D2\files\*.txt
I am trying to copy text files from this path, however FWES_0D526B00D2 directory name changes every day. ex.FWES_0D526B00D5, FWES_0D526B00D6, FWES_0D526B04Z4 etc.... Is there any ways to dynamically choose this path to pull files?
Upvotes: 0
Views: 87
Reputation: 251
If there is only one directory in 20200120 with FWES... at any given time, you should be able to use Copy-Item -Path "\\User\LS\ADMIN\HW\DATA\Payroll\20200120\FWES*\files\*.txt"
If the FWES directories are being added and the old ones still exist, this obviously won't work.
Another option would be to find the newest FWES directory based on directory creationtime attribute and from there you'll get the full path.
It looks like my first solution doesn't work with UNC paths. Try this:
$path = (Get-Item -Path "\\User\LS\ADMIN\HW\DATA\Payroll\20200120\FWES*").FullName
$path += "\files\*.txt"
Copy-Item -Path $path -Destination ""
Upvotes: 2