S
sporticia
hi
I'm trying to loop through files in a directory and then perform an
action based on a part of the name of the file. the first if is to
exclude .zip files
the second if loop is supposed to check the 6th and 7th characters and
compare them to $prevmonthint, which is a 2 character string
representing a month (so 01=Jan, 02=Feb etc.)
right now all I want it to do is if the value f $prevmonth int is say
"03", print all files where the 6th and 7th characters are also "03"
can anyone see an error in the syntax of the code below ? powershell
aint having it
(
foreach ($file in Get-ChildItem $thislogdir)
{
if (! $file.name.endswith(".zip"))
{
if ($file.name.substring(6,2) = $prevmonthint)
{
Write-Host $file
}
}
}
powershell errors with
Assignment failed because [System.String] doesn't contain a settable
property 'substring()'.
At :line:46 char:26
+ if ($file.name.substring <<<< (6,2) = $prevmonthint)
thanks for any help
_scott
I'm trying to loop through files in a directory and then perform an
action based on a part of the name of the file. the first if is to
exclude .zip files
the second if loop is supposed to check the 6th and 7th characters and
compare them to $prevmonthint, which is a 2 character string
representing a month (so 01=Jan, 02=Feb etc.)
right now all I want it to do is if the value f $prevmonth int is say
"03", print all files where the 6th and 7th characters are also "03"
can anyone see an error in the syntax of the code below ? powershell
aint having it

foreach ($file in Get-ChildItem $thislogdir)
{
if (! $file.name.endswith(".zip"))
{
if ($file.name.substring(6,2) = $prevmonthint)
{
Write-Host $file
}
}
}
powershell errors with
Assignment failed because [System.String] doesn't contain a settable
property 'substring()'.
At :line:46 char:26
+ if ($file.name.substring <<<< (6,2) = $prevmonthint)
thanks for any help
_scott