Skip to content

Instantly share code, notes, and snippets.

View nkrh's full-sized avatar

Nico Kurniawan nkrh

  • Jakarta
View GitHub Profile
@nkrh
nkrh / regex_rename.py
Created January 27, 2018 02:51
Bulk rename with Python
import os, re
path = 'C:/Users/Test/test'
pattern = '^([A-Z]+)\-([0-9]+).*$'
replace = r"\2-\1.mkv"
comp = re.compile(pattern)
for f in os.listdir(path):
full_path = os.path.join(path, f)
if os.path.isfile(full_path):
@nkrh
nkrh / rmdir_deep.bat
Created January 19, 2018 13:43
Delete a directory with Robocopy
@ECHO OFF
SET TARGET_DIR=%1
SET EMPTY_DIR=$EMPTY_DIR$
MKDIR %EMPTY_DIR%
ROBOCOPY %EMPTY_DIR% %TARGET_DIR% /PURGE
RMDIR %EMPTY_DIR%
RMDIR %TARGET_DIR%
ECHO Directory successfully removed
@nkrh
nkrh / regex_rename.bat
Created January 19, 2018 09:03
Rename files with Python
@ECHO OFF
SET PATTERN=%1
SET REPLACE=%2
python %~dp0/regex_rename.py %PATTERN% %REPLACE%