Windows - Batch script- How to Append Current Date and Time to .txt name

StackOverflow https://stackoverflow.com/questions/22316089

  •  12-06-2023
  •  | 
  •  

Pergunta

I know this question was duplicated many time and I tried almost all of it but I still unable to append date and time to a .txt . Sorry if this question make you mad or anything.

Here is my code:

cd C:\Users\310152922\Desktop\Mohit Task\Lumi_FTP
java Lumi_FTP "C:\Users\310152922\Desktop\Mohit Task\Lumi_FTP\lumi_ftp_settings.ini" >"C:\test\Scriptlogs\log_DP.txt"

exit;

The question is is how can I append date and time to a "name" of a .txt Example (expecting output): log_DP_DATE_ TIME.txt (log_DP_03112014_1146.txt)

Thank you very much for viewing, comment and answer.

p.s I m newbie for programming languages

Foi útil?

Solução

The first four lines of this code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher.

The variable is in the log file name below:

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & 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 "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"

cd /d "C:\Users\310152922\Desktop\Mohit Task\Lumi_FTP"
java Lumi_FTP "C:\Users\310152922\Desktop\Mohit Task\Lumi_FTP\lumi_ftp_settings.ini" >"C:\test\Scriptlogs\log_DP_%fullstamp%.txt"
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top