Skip to content

Instantly share code, notes, and snippets.

@Kochise
Last active December 12, 2019 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kochise/bb7c957adf6bb6dc558961142a7d118f to your computer and use it in GitHub Desktop.
Save Kochise/bb7c957adf6bb6dc558961142a7d118f to your computer and use it in GitHub Desktop.
Rename Github repository archive (-master -> -yyyymmdd) /!\ needs 7Zip
@echo off
rem For correct string substitution, need delayed variable expansion
rem Beware: you'll scratch your head several times with this shit
setlocal enabledelayedexpansion
rem Set this variable to get some fancy debug output
set "vdeb="
set "fdir=dir *-master.zip /B /A:-D /ON /S"
for /f %%a in ('!fdir!') do (
if not "!vdeb!"=="" echo a=%%a
set "fold=%%~nxa"
if not "!vdeb!"=="" echo fold=!fold!
"c:\Program Files\7-Zip\7z.exe" l "%%a" >liste.txt
for /f "tokens=1 delims= " %%b in ('findstr /e /c:"%%~na" liste.txt') do set "fdate=%%b"
if not "!vdeb!"=="" echo fdate1=!fdate!
for /f "tokens=1,2,3,4 delims=-" %%b in ("!fdate!") do set "fdate=%%b%%c%%d%%e"
set "fdate=!fdate: =0!"
set "fdate=!fdate:~2!"
if not "!vdeb!"=="" echo fdate2=!fdate!
call set "fnew=%%fold:-master=-!fdate!%%"
if not "!vdeb!"=="" echo fnew=!fnew!
ren "%%a" "!fnew!"
)
del /f liste.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment