I've pieced together this script to try and move a file from a folder to another, and add a date to the end of the file. It worked once, but hasn't worked since. This is my first script, and I was hoping an expert would take a look and advise if they see something wrong here. Any assistance would be greatly appreciated.

@echo off

move "c:\ic\test source\*.*" "c:\test destination"
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%

set stamp=%YYYY%%MM%%DD%_%HH%%Min%%Sec%

Here is a PowerShell script I wrote to do what you were looking for.

$SourcePath = "c:\test\*.txt"
$DestPath = "c:\test2\"

$Files = Get-ChildItem -path $SourcePath

foreach ($File in $files)
      $DateTime =   get-date -format "yyyyMMddhhmmss"
      $NewName = $DestPath + $file.basename + " " + $DateTime +  $file.Extension
      Move-Item -path $file.FullName -Destination $NewName -Verbose

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.