Create File Name with Day of the Week

Asked

Viewed 1,017 times

4

I need to create a routine that does the backup with the name of day of week in order to comply with the following layout:

Example: backup_01012019_second.7z

The closest you could find that didn’t help me was the code below:

for /F "tokens=2 skip=2 delims=," %%D in ('WMIC Path Win32_LocalTime Get DayOfWeek /Format:csv') do @echo %%D

1 answer

3


-Update: + Speedy for date|day|week and compacted|shortened in the code :


@echo off & setlocal enableextensions enabledelayedexpansion & set "_do=Get Day^,Month^,Year^,DayOfWeek" 
(set "_ds=0Domingo,1Segunda,2Terca,3Quarta,4Quinta,5Sexta,6Sabado," && for /f "tokens=1-4delims= " %%a in ('wmic Path Win32_LocalTime 
^!_do!^|findstr /r [0-9]')do set "_d=0%%a" & set "_m=0%%c" & set "_data=!_d:~-2!_!_m:~-2!_%%~d" & set _x=%%b & for %%x in (!_ds!)do ^
echo/%%x|findstr /blic:!_x! >nul && (set "_s=%%x" & set "_data=!_data!_!_s:~1!")) & set "_backup_file=backup_!_data!.7z" & echo/!_backup_file!

| Results | backup_22_04_2019_Segunda.7z


  • Bat • For compose the layout of name of filing cabinet catching the dice of date ( with "0" in front of day/month less than 10) and adding the day of week in the filename

@echo off & @setlocal enabledelayedexpansion

set "_dias_=0-Domingo,1-Segunda,2-Terca,3-Quarta,4-Quinta,5-Sexta,6-Sabado"

for /f "tokens=1-4 delims= " %%a in ('WMIC Path Win32_LocalTime Get Day^,Month^,Year^,DayOfWeek^| findstr /r "[0-9]"') do (
    if not %%a geq 10 (set "_data=0%%a") else (set "_data=%%~a")
    if not %%c geq 10 (set "_data=!_data: =!0%%c") else (set "_data=!_data: =!%%~c")
    set "_data=!_data!%%d" & set "DayOfWeek=%%b"
    )
for %%d in (!_dias_!)do for /F %%D in ('echo/!DayOfWeek!') do (
    for /f "tokens=1,2delims=-" %%1 in ('echo/%%d') do if "%%D" equ "%%1" set "_data=!_data!_%%2"&&goto :_next_:
    )

:_next_:
set _backup_file=backup_!_data!.7z
echo/ !_backup_file!

| Results | backup_22_04_2019_Segunda.7z


  • Thank you very much. Perfect.

  • Obs. If you want the name of the whole day of the week in lowercase, eh soh edit the variable days.

  • Thanks for the tip. The edition is good to do.

  • I wonder if you could help me here: https://answall.com/questions/242536/inclu-tarefa-no-scheduler-tasks-do-windows-via-batch

Browser other questions tagged

You are not signed in. Login or sign up in order to post.