-1

i started as programmer from 2 month ago with batch programming.

i wanted to make a batch file that can make a back up file as (file - 2022 03 30 11 51) so i studied batch scripting syntax on internet n wrote scripts below

e:
setlocal
set year=%date:~0,4%
set month=%date:~5,2%
set date=%date:~2,2%
set hour=%time:~0,2%
set minute=%time:~3,2%
set second=%time:~6,2%
mkdir temp
echo y|copy "#.xmind" "temp"
cd temp
ren "#.xmind" "# - %year% %month% %date% %hour% %minute%.xmind"
echo %date% %time%
echo "%year% %month% %date% %hour% %minute%.xmind"
pause

but %date% is not written as date of today... could u please, revise this script if u can or recommand another new script as batch script?

Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • 1
    The date format depends on user settings. You would need to show us what is displayed by `echo %date% %time%` for you. Please edit that information into your question. – Magoo Mar 30 '22 at 05:36

1 Answers1

1

a Much more reliable method to get the date and format it accordingly would be to use the help of powershell:

@echo off
mkdir "E:\temp">nul 2>&1 & (pushd "E:\temp" || exit /b 1)
copy /y "..\#.xmind" .
for /f "delims=" %%i in ('Powershell.exe get-date -Format 'yyyy MM dd HH mm'') do ren "#.xmind" "# - %%i.xmind"
popd
Gerhard
  • 22,678
  • 7
  • 27
  • 43