Author Topic: [BAT] Apply File Properties to Foldername  (Read 524 times)

0 Members and 1 Guest are viewing this topic.

Offline HcH

  • TechKnow Owner, Ethical Hacker
  • Administrator
  • Uber Member
  • *****
  • Posts: 9956
  • Karma: +2285/-111
[BAT] Apply File Properties to Foldername
« on: August 29, 2017, 11:26:25 PM »
Here's a nice nifty script that handles a action per directory per type of file.
This example came in handy when I was sorting some game collection, I wanted the date of each folder's .exe file to be appended to the directory name of each game. Basically you can easily modify this to do whatever you want :)

@echo off

setlocal enabledelayedexpansion

REM :::::::::::::::::::::
REM :::::::::::::::::::::

for /F "tokens=* delims=" %%i in ('dir /ad /b') do (

echo -----------------------------------------------------------------------------

echo Parsing dir "%%i" ...
for /F "tokens=* delims=" %%j in ('dir /b "%CD%\%%i\*.exe"') do (

echo Parsing file "%CD%\%%i\%%j" ...
for %%a in ("%CD%\%%i\%%j") do set FileDate=%%~ta
echo FD !FileDate!
set year=!FileDate:~6,4!
echo Year !year!
ren "%CD%\%%i" "%%i [!year!]")

echo -----------------------------------------------------------------------------