Skip to content

Instantly share code, notes, and snippets.

@aembleton
Created October 15, 2013 14:38
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 aembleton/6992585 to your computer and use it in GitHub Desktop.
Save aembleton/6992585 to your computer and use it in GitHub Desktop.
Renames files that have a name ending in 20131015-140115.csv to the current date in the format yyyyMMdd then a -, then the number already in the file name, incremented by 1. File ending in 20131015-140115.csv ran through this script on 1 January 2014 will have their ending renamed as 20130101-140116.csv
@echo off
setlocal enabledelayedexpansion
set FOLDER_PATH=.
set year=%date:~-4%
set month=%date:~3,2%
set day=%date:~0,2%
pushd %FOLDER_PATH%
for %%f in (*csv) do if %%f neq %~nx0 (
set "filename=%%~nf"
set "postfix=!filename:~-6!"
set /a postfix=postfix+1
set "filename=!filename:~0,-15!"
ren "%%f" "!filename!!year!!month!!day!-!postfix!%%~xf"
)
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment