-2

Copy directories if their subdirectories contain "connect.txt" I want to copy multiple directories from one location to another location only if any of the subdirectories of those contain the connect.txt file in them.

Example:

C:\ANIMAL\DOG\CONNECT.TXT
C:\PLANET\EARTH\CONNECT.TXT
C:\SYSTEM\USER\ADMIN.TXT

Then I ONLY want to copy ANIMAL & PLANET directories to C:\DESKTOP.

INPUT :

C:\ANIMAL\TIGER\CONNECT.TXT
C:\ANIMAL\LION\WILD.TXT
C:\PLANET\EARTH\CONNECT.TXT
C:\SYSTEM\USER\ADMIN.TXT
C:\SYSTEM\USER\DOG.TXT
C:\SYSTEM\USER\CAT.TXT

OUTPUT:

C:\DESKTOP\ANIMAL
C:\DESKTOP\EARTH
Toni
  • 1
  • 1
  • 1
    Well, this is neither a tutorial site nor a free coding service, so I am afraid you are wrong here. This is a question-and-answer place for programming-specific issues. Please read the [tour] and read [ask] and [mcve] to learn how to use this site! Starting point: [`for /D`](https://ss64.com/nt/for_d.html), [`if exist`](https://ss64.com/nt/if.html), [`move`](https://ss64.com/nt/move.html)... – aschipfl Jun 11 '19 at 19:19
  • 2
    Toni, please don't insult us, changing `Copy` to `Move` in the titles, doesn't really show us that you're willing to learn something. – Compo Jun 11 '19 at 20:46
  • Thank you for the suggestion – Toni Jun 12 '19 at 17:22

1 Answers1

0

maybe something like

powershell.exe -executionpolicy unrestricted -encodedCommand RwBlAHQALQBDAGgAaQBsAGQASQB0AGUAbQAgAC0AUABhAHQAaAAgACcAQwA6AFwAJwAgAC0ARgBpAGwAdABlAHIAIAAnAEMAbwBuAG4AZQBjAHQALgB0AHgAdAAnACAALQBSAGUAYwB1AHIAcwBlACAALQBFAHIAcgBvAHIAQQBjAHQAaQBvAG4AOgBJAGcAbgBvAHIAZQAgAC0ARQB4AGMAbAB1AGQAZQAgACcAQwA6AFwARABlAHMAawB0AG8AcABcACoAJwAgAHwAIABGAG8AcgBFAGEAYwBoAC0ATwBiAGoAZQBjAHQAIAB7ACQAXwAuAEQAaQByAGUAYwB0AG8AcgB5AH0AIAB8ACAAQwBvAHAAeQAtAEkAdABlAG0AIAAtAEQAZQBzAHQAaQBuAGEAdABpAG8AbgAgACcAQwA6AFwARABlAHMAawB0AG8AcABcACcAIAAtAEMAbwBuAHQAYQBpAG4AZQByACAALQBGAG8AcgBjAGUAIAAtAFIAZQBjAHUAcgBzAGUAIAAtAEMAbwBuAGYAaQByAG0AOgAkAGYAYQBsAHMAZQAgAC0ARQByAHIAbwByAEEAYwB0AGkAbwBuADoASQBnAG4AbwByAGUA

whereas the encoded command for the following stands:

Get-ChildItem -Path 'C:\' -Filter 'Connect.txt' -Recurse -ErrorAction:Ignore -Exclude 'C:\Desktop\*' | ForEach-Object {$_.Directory} | Copy-Item -Destination 'C:\Desktop\' -Container -Force -Recurse -Confirm:$false -ErrorAction:Ignore

(But don't trust me, copy the characters above in a base64 to text online converter and see for yourself!)

Christoph
  • 3,322
  • 2
  • 19
  • 28