Skip to content

Instantly share code, notes, and snippets.

@aembleton aembleton/rename.bat
Created Oct 15, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.