Could you try doing this? Im just really confused and not really understanding :/
I believe that there is an ancient proverb that goes something like this: Give a man a fish and you feed him for one day. Teach a man how to fish and you feed him for a lifetime.
Sure, I could write it, but then if you ever want to modify it you'll be back to being really confused. So while this might be painful, in the long run you will benefit from learning more about PS.
While you can reference $files as an array in C++ format, with PS there is an easier way. Paste this into Powershell_ise and run it.
$files = @("File1","File2")
foreach ($file in $files){
"robocopy this file: {0} " -f $file
}
Update: I took the $files variable name too literally. I would expect you to have folder names in that array.
More to come...
Create variables for the source and destination folders. It will make it easier to reference/change them. And if you process the robocopy log each time, instead of appending to one big log file, it might be easier. Add in the code that I posted in a previous comment and see if you can parse the log.
$srcFolder ='C:\temp\Src'
$dstFolder ='C:\temp\dst'
$folders = @("Foo1")
$logfile = "C:\temp\robocopylog.txt"
foreach ($f in $folders){
"Source is {0} " -f "$srcFolder\$f"
"Destination is {0} " -f "$dstFolder\f"
robocopy.exe "$srcFolder\$f" "$dstFolder\$f" /e /l /unilog:$Logfile
$log = Get-Content $logfile # read in the log for this run of robocopy, append it to a "job" log if you want all of the logs saved
$capture = $false # have we found where the file names start?
foreach ($l in $log) {
if ($l -match " Total Copied Skipped ") {
"We found the ending point!"
$capture = $false
}
if (($capture) -and ($l -notmatch '-----------') -and ($l.trim() -ne '')) { # ignore blank and separator lines
$l # show the line to process
# add code here to look for lines that start with "New Dir", Save the directory name
# look for "New File", this line has the file size and file name.
# use .substring methods to parse the data you
# https://www.itechguides.com/powershell-substring/#:~:text=%20How%20to%20Extract%20a%20Powershell%20Substring%20from,may%20want%20to%20extract%20a%20PowerShell...%20More%20
}
if ($l -match " Options : ") {
"We found a starting point!"
$capture = $true
}
}
}