0
votes

I have a question I would like to copy a file where I know the path into a folder. The folder is always created according to a certain scheme, e.g. "MyFolder-RANDOMSTRING".

With the following command I can display the folder :

Get-ChildItem "C:\Users\User\AppData\Local" -Recurse -Directory -Filter "MyFolder-*

But how can I now copy a file with Copy-Item into the unknown RANDOMSTRING folder ?

1
Take a look at this, it's a similar problem: stackoverflow.com/questions/61632864/…AdamL

1 Answers

0
votes

You can do:

$directory_path = ( Get-ChildItem "C:\Users\User\AppData\Local" -Recurse -Directory -Filter 'MyFolder-*' ).FullName
Copy-item 'File path of file to be copied' -Destination  $directory_path