2
@echo off

set "src_dir=C:\Users\\Documents\projects\Config\ABC"
set OUTFILE="C:\Users\Documents\Scriptoutput.txt"

echo %OUTFILE%
pushd %cd%
cd %src_dir%

for /r %%f in (*) do (  
      (
        <nul set /p ".= %%~dpnxf," 
        certutil -hashfile "%%f" MD5 | find /V ":"
      ) >>%OUTFILE%  
   )

Out file content now:

C:\Users\Documents\Projects\Config\common\abc.csv,e71073e6906e06223d184fcd91124aad
C:\Users\Documents\Projects\Config\common\def.csv,6c3f42be2f7a19a31f2002accab8273d
C:\Users\Documents\Projects\Config\common\ahi\ghi.csv,d62d1612d82eff53038ccbd4eb32a81f
C:\Users\Documents\Projects\Config\common\ahi\ert.csv,8425dbd884c27a0ba4615ef5c45b97e5

Expected:

Config\common\abc.csv,e71073e6906e06223d184fcd91124aad
Config\common\def.csv,6c3f42be2f7a19a31f2002accab8273d
Config\common\ahi\ghi.csv,d62d1612d82eff53038ccbd4eb32a81f
Config\common\ahi\ert.csv,8425dbd884c27a0ba4615ef5c45b97e5
Io-oI
  • 9,237
Sam sh
  • 21

1 Answers1

3
@echo off

subst .: "%UserProfile%\Documents\Projects"
cd /d .:\ && 2>nul call del /q /f /a: ".:\Output.txt"

for /f delims^= %%i in =;(' where /r . *.* ^| find /v /i "\Output.txt" ');= do set "_path=%%~pnxi" && <nul =;( 
     call set /p ".=%%_path:~1%%," & certutil -hashfile "%%~fi" MD5 | find /v ":" );= >>".:\Output.txt"

type ".:\Output.txt" & cd /d "%~dp0" & subst /d .:

  • Or specifically list the *.csv files if this is your case, optionally, you can also list more extensions with: where /r . *.xlsx *.csv:
@echo off

subst .: "%UserProfile%\Documents\Q1833755\Projects" cd /d .:\ && 2>nul call del /q ".:\Output.txt"

for /f delims^= %%i in =;(' where /r . *.csv ');= do set "_path=%%~pnxi" && <nul =;( call set /p ".=%%_path:~1%%," & certutil -hashfile "%%~fi" MD5 | find /v ":" );= >>".:\Output.txt"


1. Create a drive to replace your root folder, like .:

2. Associate it with a character that will prevent graphical access (Windows/Explorer)

3. Enter that drive, list your files and remove the first character with substring in varible

4. Finally, remove the created drive, list/check your output



Additional resources:

Io-oI
  • 9,237