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


#*******************************************************************  #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 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"      }          # path extension (hint: there none!)      $extension = [system.io.path]::getextension($file)      "getextension('{0}') returns '{1}'" -f $dirvan, $extension        if($extension.length -le 0)      {        #echo file has no extention created      write-host "the file has no extention, .tif extention made"        ## create file extention ?? // how ??? !! --> need rename file no extention in directory $dirvan        }      else      {             write-host "the file being copied"             copy-item $dirvan $dirna -filter "*.tif"      }    }  

a sample rename be 

gci c:\temp -file | extension -eq "" | foreach-object {rename-item -path "$($_.fullname)" -newname "$($_.basename).tif"}


sumesh p.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group