Thanks @Mofi, see his comments below the starting post!
This is a solution for а Folder
on (any) user's Desktop
:
for /f "delims=" %%i in ('dir "%UserProfile%\Desktop\Folder\*.txt" /a-d /b /on /s 2^>nul') do (
echo %%~fi>> result.txt
type "%%i">> result.txt
echo(>> result.txt
)
echo %%~fi>> result.txt
adds full path to any *.txt file found in
that folder (and subfolders);
type "%%i">> result.txt
merges found *.txt files
contents;
echo(>> result.txt
is the new line character requested!
This code tested on NTFS and is promised to work on FAT\FAT32 etc. - unlike for /R
(see @Mofi comments below the starting post!).
P.S.: you can launch this batch code from any location; also, use echo {anytext}>> result.txt
after echo(>> result.txt
to easily navigate between breaks in "result.txt" :)
P.P.S.: also, if you want to get rid of blank line in the EOF "result.txt" - use this:
set /a counter1=0
set /a counter2=0
::cycle 1
for /f "delims=" %%i in ('dir "%UserProfile%\Desktop\Folder\*.txt" /a-d /b /on /s 2^>nul') do (
set /a counter1+=1
)
::cycle 2
setlocal enableextensions enabledelayedexpansion
for /f "delims=" %%i in ('dir "%UserProfile%\Desktop\Folder\*.txt" /a-d /b /on /s 2^>nul') do (
echo %%~fi>> result.txt
type "%%i">> result.txt
set /a counter2+=1
if not !counter2!==%counter1% (echo(>> result.txt)
)
endlocal
Inspired by: https://stackoverflow.com/a/7522822/6859021
- both cycles has the same
for /f
conditions;
::cycle 1
counts number of files that are about to undergo the procedure;
::cycle 2
is identical to original solution, except for "Inspired
by" details;
::*
lines are comments: they don't affect code
execution;
if not !counter2!==%counter1% (echo(>> result.txt)
merely puts echo(
for all lines, except for the last one! :D
Notice however that counters will work properly only if "result.txt" will NOT be located inside Folder
of interest, or it's subfolders.