Score:0

Issues with robocopy /xf switch when using a variable for the /xf in powershell

cn flag

I've got a cleanup job that is running daily to clean a number of directories based on a csv file. The CSV file contains the following:

SourceFolder,MinAge(Days),SubDirectories(Y/N?),ExcludeItems
TEST,0,N,*.txt;*.csv;*.bmp
TEST2,0,N,*.csv;*.bmp

I'm extracting the ExcludeItems data using:

$ExcludeItems = $ExcludeItems.Replace($separator,",")
$ExcludeItems = "`" + $ExcludeItems`""

Mind you I've tried multiple different ways of constructing this variable

And my robocopy statement is as follows:

robocopy $sourceFolder $purgeFolder /XF $ExcludeItems /COPY:DT /DCOPY:T /MOV /E /MINAGE:$OlderThan /r:10

With the $sourceFolder and $purgeFolder previously constructed based on the environment.

Everything was working fine until the /XF switch was included which no matter how I construct the $ExcludeItems it either excludes nothing or only one of the file types.

Any suggestions?

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.