Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows powershell file process duplication

Status
Not open for further replies.

csharpenthusiast007

Programmer
Aug 22, 2016
2
US
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.
 
Could -recurse be the answer you are looking for

$orgFolder = Get-ChildItem -Path "C:\Temp\" -[highlight #FCE94F]Recurse[/highlight] -Exclude *.*

Many Thanks
Yurov Ardyy
 
Could -recurse be the answer you are looking for

$orgFolder = Get-ChildItem -Path "C:\Temp\" -[highlight #FCE94F]Recurse[/highlight] -Exclude *.*

Many Thanks
Yurov Ardyy
 
Could -recurse be the answer you are looking for

$orgFolder = Get-ChildItem -Path "C:\Temp\" -Recurse -Exclude *.*

Many Thanks
Yurov Ardyy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top