csharpenthusiast007
Programmer
My folder structure is "C:\Temp\SalesOrder\20160809\cc.txt" when its looking for all the files that need to be processed as soon as the recursion gets to folder "C:\Temp\SalesOrder" & "C:\Temp\SalesOrder\20160809" its processing cc.txt file. How do I rewrite the gci to not to traverse subfolders and only process files "C:\Temp\SalesOrder\20160809"
$flatFilePath = "C:\Temp\Email.csv"
$flatFile = Import-Csv -Path $flatFilePath -Header Dir,Email
$emailID = @{}
foreach ($record in $flatFile) { $emailID[$record.Dir]=$record.Email }
# organization folder
$orgFolder = Get-ChildItem -Path "C:\Temp\" -Recurse -Exclude *.*
# Send email
foreach ($dir in $orgFolder) {
$processedfiles = $null
$emailTo = $null
Get-ChildItem -Path $dir.FullName -Recurse -Include *.txt,*.xls,*.csv,*.xlsx | ? { $_.FullName } |
Foreach-Object {
[string]$internalOrg = [System.IO.DirectoryInfo]$_.Directory.Name
$processedfiles += [string][System.IO.Path]::GetFileName($_.FullName) + " | ";
}
$emailTo = $emailID.Get_Item($dir.Name) -split ";"
if ($processedfiles) { Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body "$Body $processedfiles" -SmtpServer $SMTPServer -port $SMTPPort }
}
Problem area:
Get-ChildItem -Path $dir.FullName -Recurse -Include *.txt,*.xls,*.csv,*.xlsx | ? { $_.FullName } |
Foreach-Object {
[string]$internalOrg = [System.IO.DirectoryInfo]$_.Directory.Name
$processedfiles += [string][System.IO.Path]::GetFileName($_.FullName) + " | ";
}
Thank you.
$flatFilePath = "C:\Temp\Email.csv"
$flatFile = Import-Csv -Path $flatFilePath -Header Dir,Email
$emailID = @{}
foreach ($record in $flatFile) { $emailID[$record.Dir]=$record.Email }
# organization folder
$orgFolder = Get-ChildItem -Path "C:\Temp\" -Recurse -Exclude *.*
# Send email
foreach ($dir in $orgFolder) {
$processedfiles = $null
$emailTo = $null
Get-ChildItem -Path $dir.FullName -Recurse -Include *.txt,*.xls,*.csv,*.xlsx | ? { $_.FullName } |
Foreach-Object {
[string]$internalOrg = [System.IO.DirectoryInfo]$_.Directory.Name
$processedfiles += [string][System.IO.Path]::GetFileName($_.FullName) + " | ";
}
$emailTo = $emailID.Get_Item($dir.Name) -split ";"
if ($processedfiles) { Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body "$Body $processedfiles" -SmtpServer $SMTPServer -port $SMTPPort }
}
Problem area:
Get-ChildItem -Path $dir.FullName -Recurse -Include *.txt,*.xls,*.csv,*.xlsx | ? { $_.FullName } |
Foreach-Object {
[string]$internalOrg = [System.IO.DirectoryInfo]$_.Directory.Name
$processedfiles += [string][System.IO.Path]::GetFileName($_.FullName) + " | ";
}
Thank you.