I have a vendor who sends 5-10 files a month. Recently they started sending us a mixture of Unix format files among the Windows format files. This vendor is notoriously difficult to work with so this problem will be quicker solved by myself.
I have a short Powershell 7 script that works for the Unix files but creates havoc with the Windows files:
$Files = Get-ChildItem '\XD1Vendor_Incoming*.csv'
foreach($file in $Files){
(Get-Content -Raw -Path $file) -replace "`n","`r`n" | Set-Content -NoNewline -Path $file
}
After searching SO and general google searches, I have yet to find an efficient method to test each file for its file format within the foreach statement, something like:
foreach($f in $Files){ If(thisfileisUnix){Process-File} }
Thank you for your time.