Hi,
We get files like this from vendor
aaa.bbb.dat
xxxYYY
dddd.eee
zzzzz.dat
ffff.txt
I need to get all the files without extension (in this example xxxYYY and dddd.eee) and add .dat extension to them.
After I add extension, files should look like this in the folder:
aaa.bbb.dat
xxxYYY.dat
dddd.eee.dat
zzzzz.dat
ffff.txt
The code I tried:
$files = Get-ChildItem "\\rootfolder\reports"
********************* STE2: Loop through all the files and check for .dat extension. If there is no extension, add extension to the file
foreach ($f in $files){
$outfile = $f.FullName
$fileName = $f.Name
if ($fileName -Like "*.dat")
{
#do nothing
}
else
{
$newName = $fileName + ".dat"
Rename-Item -Path $outfile -NewName $newName
}
} # end of for loop
I don't like this code because if there is file with .txt extension, it adds .dat to the file. Any other way of getting only list of files that don't have extension and then add .dat.
I don't want to limit my filter criteria to .dat or .txt if I can.
In my logic I should get only files that don't have extension and add .dat to them.
Thank You