Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

How can i rename a file in a specific directory if the file has no exention to a file with a .tif extention in Powershell ?

$
0
0

#*******************************************************************

#Auteur: Casper Limburg

#*******************************************************************

#*******************************************************************

#cleans screen

#*******************************************************************

cls

#*******************************************************************

# Declare variable & constrains

#*******************************************************************

$DirVan = "C:\BestandVerplaatsen\van\*"

$DirNa = "C:\BestandVerplaatsen\naar"

$File = Get-ChildItem $DirVan #| Where-Object {$_.Extension -eq ".txt"}

#*******************************************************************

# if files in directory copy to specific place

#*******************************************************************

foreach ($File in $DirVan){

#If no txt files found...

if (!(gci $DirVan *.txt))

{

write-host "No text files!"

}

#If txt files found...

if (gci $DirVan *.txt)

{

copy-item $DirVan $DirNa -filter "*.txt"

}

# Get Path Extension (hint: there is none!)

$extension = [System.IO.Path]::GetExtension($File)

"GetExtension('{0}') returns '{1}'" -f $DirVan, $extension

if($extension.Length -le 0)

{

#echo file has no extention this will be created now

write-host "The File has no extention, a .tif extention will be made"

## create file extention ?? // HOW ??? HELP !! --> i need to rename a file with no extention in directory $DirVan

}

else

{

write-host "The file is being copied"

copy-item $DirVan $DirNa -filter "*.tif"

}

}

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles