Windows batch file ren using date variable -


learned batch while ago in school, haven't ever used until b/c had idea. fun wanted mess around powercfg batteryreport new laptop, want archive. going try , figure out how have file powercfg batteryreport spits out changed in sort of numerical order don't know begin, decided make new line takes current file created , adds date. of taking place inside of special folder created, pathing isnt necessary.

    @echo off     powercfg batteryreport     rename "battery-report.html" "batteryreport %date%.html" 

this exact script works without date variable, never in, of course need variable present in order have multiple reports saved, opposed writing on every time. i've tried messing spacings, quotes vs no quotes, no luck. (or better way, preferably explanation) appreciated.

in likelihood, date format contains / illegal in filename.

use %date:/=-% in place of %date%. converts each / - (see set /? prompt docco)

equally, use %time::=.% o convert time version usable in filename.


to remove dayname, need use intermediate variable:

set "dateonly=%date:* =%" ren ... "...%dateonly:/=-%..." 

the * means "all of characters , including first space" , replaced nothing (the string following =)

see set /? prompt details.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -