0

i have a script that gets "app_sub.txt" everyday and renames it with process date&time stamp "app_sub-2014-09-17@07-21" and moves it in different folder.

$conCAdir1 = "C:\Udata\CommonApp\"
$conCAdir1pro = "C:\Udata\CommonApp\PROCESSED\"
$conCAfile1 = "app_sub.txt"

$FQFN = $conCAdir1 + $conCAfile1
if (Test-Path $FQFN) {
   
  $fileObj = Get-Item $FQFN
  $Fsize = [System.Math]::Round($fileObj.length/1KB)
  $DateStamp = Get-Date -uformat "%Y-%m-%d@%H-%M"
  $extOnly = $fileObj.extension
  $nameOnly = $fileObj.Name.Replace( $fileObj.Extension,'')
  $Filer = "$nameOnly-$DateStamp$extOnly"
   
 
  If ($UPDATE) {
    Rename-Item $FQFN $Filer
    Move-Item "$conCAdir1$Filer" $conCAdir1pro
  } # $UPDATE
}  # Test-Path

But now instead of "app_sub.txt" i'm getting file with current date "App_sub_09162014.txt". How do i get the file with date and do the same rename & moving process?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52

1 Answers1

0

Got the Answer from another post.

$conCAfile1 = gci $conCAdir1 | select -last 1