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

0 Members and 1 Guest are viewing this topic.

Offline Stephan

  • TechKnow Owner
  • Administrator
  • Uber Member
  • *****
  • Thank You
  • -Given: 3697
  • -Received: 1128
  • Posts: 9636
  • Karma: +2278/-106
[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 :: GET-FILEDETAILS ::
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 -----------------------------------------------------------------------------

)

pause

 

Powered by EzPortal