Skip to content

Batch file to create filelist.txt and dummy library from it

Benjamin Brisson edited this page Feb 26, 2021 · 6 revisions

Batch file to create filelist.txt or re-create a library from the filelist with 0 size files


@ECHO OFF
REM 1 - if no filelist create filelist no folders
REM 2 - if file there restore
chcp 1251>nul

IF EXIST filelist.txt goto RESTORE
ECHO Press Enter to create listfile.txt containing all files relative path
rundll32 user32.dll,MessageBeep -1
PAUSE
SETLOCAL DisableDelayedExpansion
SET "r=%__CD__%"
type nul > filelist.txt
FOR /R . %%F IN (*) DO (
  SET p=%%F
  SETLOCAL EnableDelayedExpansion
  ECHO(!p:%r%=!
  ENDLOCAL
) >> filelist.txt
ECHO [filelist.txt] created list
rundll32 user32.dll,MessageBeep -1
GOTO EXIT

:RESTORE
ECHO Press enter to create all dummy files from filelist.txt
rundll32 user32.dll,MessageBeep -1
PAUSE
rem for /f "tokens=2 delims=:." %%x in ('chcp') do set cp=%%x
rem chcp 437>nul

REM IMPORTANT LOOP DOING ALL THE WORK
for /f "tokens=*" %%a in (filelist.txt) do (
IF NOT EXIST "%%~pa" mkdir "%%~pa"
IF NOT EXIST "%%a" TYPE nul > "%%a"
)
rem chcp %cp%>nul
ECHO [filelist.txt] processed, blank files created
rundll32 user32.dll,MessageBeep -1
GOTO EXIT

:EXIT
ECHO Finished!
PAUSE