Skip to main content
added 1063 characters in body
Source Link
MC ND
  • 1.5k
  • 10
  • 13
@echo off
    setlocal enableextensions disabledelayedexpansion
    
    set "root=%cd%"
    
    >"output.doc" (
        for /f "tokens=2,*" %%a in ('
            robocopy "%root%\." "%root%\." *.txt /l /s /is /ts /ndl /njh /njs /nc /ns 
            ^| sort 
        ') do type "%%~fb"
    )

This will use robocopy to get the list of all the .txt files under the indicated root folder.

The list of files is generated including the last modified date of the files. robocopy prints the UTC time in yyyy/mm/dd hh:mm:ss format, so the list can be properly sorted.

The rest of the code is just a for /f command to process the final list, retrieving the file reference and typing it. The full command is redirected to the output file to avoid the open/close operation for each processed file.

edited as it is needed to include the file name and the timestamp in the final output ...

@echo off
    setlocal enableextensions disabledelayedexpansion

    set "root=%cd%"

    >"output.doc" (
        for /f "tokens=1,2,*" %%a in ('
            robocopy "%root%\." "%root%\." *.txt /l /s /is /ts /ndl /njh /njs /nc /ns 
            ^| sort 
        ') do (
            echo(%%~nc
            echo(%%a %%b [%%~tc]
            type "%%~fc"
        )
    )

The tokens clause has been changed to retrieve the timestamp from robocopy so we can include it in the output. %%a will hold the date, %%b the time and %%c the file name with full path.

For each file, it is first echoed the file name without extension (%%~nc), then the robocopy time stamp and, just to compare as the output of robocopy is a UTC time, the file timestamp (%%~tc). Then the file is typed.

As before, all the output is redirected to the final file.

@echo off
    setlocal enableextensions disabledelayedexpansion
    
    set "root=%cd%"
    
    >"output.doc" (
        for /f "tokens=2,*" %%a in ('
            robocopy "%root%\." "%root%\." *.txt /l /s /is /ts /ndl /njh /njs /nc /ns 
            ^| sort 
        ') do type "%%~fb"
    )

This will use robocopy to get the list of all the .txt files under the indicated root folder.

The list of files is generated including the last modified date of the files. robocopy prints the UTC time in yyyy/mm/dd hh:mm:ss format, so the list can be properly sorted.

The rest of the code is just a for /f command to process the final list, retrieving the file reference and typing it. The full command is redirected to the output file to avoid the open/close operation for each processed file.

@echo off
    setlocal enableextensions disabledelayedexpansion
    
    set "root=%cd%"
    
    >"output.doc" (
        for /f "tokens=2,*" %%a in ('
            robocopy "%root%\." "%root%\." *.txt /l /s /is /ts /ndl /njh /njs /nc /ns 
            ^| sort 
        ') do type "%%~fb"
    )

This will use robocopy to get the list of all the .txt files under the indicated root folder.

The list of files is generated including the last modified date of the files. robocopy prints the UTC time in yyyy/mm/dd hh:mm:ss format, so the list can be properly sorted.

The rest of the code is just a for /f command to process the final list, retrieving the file reference and typing it. The full command is redirected to the output file to avoid the open/close operation for each processed file.

edited as it is needed to include the file name and the timestamp in the final output ...

@echo off
    setlocal enableextensions disabledelayedexpansion

    set "root=%cd%"

    >"output.doc" (
        for /f "tokens=1,2,*" %%a in ('
            robocopy "%root%\." "%root%\." *.txt /l /s /is /ts /ndl /njh /njs /nc /ns 
            ^| sort 
        ') do (
            echo(%%~nc
            echo(%%a %%b [%%~tc]
            type "%%~fc"
        )
    )

The tokens clause has been changed to retrieve the timestamp from robocopy so we can include it in the output. %%a will hold the date, %%b the time and %%c the file name with full path.

For each file, it is first echoed the file name without extension (%%~nc), then the robocopy time stamp and, just to compare as the output of robocopy is a UTC time, the file timestamp (%%~tc). Then the file is typed.

As before, all the output is redirected to the final file.

Source Link
MC ND
  • 1.5k
  • 10
  • 13

@echo off
    setlocal enableextensions disabledelayedexpansion
    
    set "root=%cd%"
    
    >"output.doc" (
        for /f "tokens=2,*" %%a in ('
            robocopy "%root%\." "%root%\." *.txt /l /s /is /ts /ndl /njh /njs /nc /ns 
            ^| sort 
        ') do type "%%~fb"
    )

This will use robocopy to get the list of all the .txt files under the indicated root folder.

The list of files is generated including the last modified date of the files. robocopy prints the UTC time in yyyy/mm/dd hh:mm:ss format, so the list can be properly sorted.

The rest of the code is just a for /f command to process the final list, retrieving the file reference and typing it. The full command is redirected to the output file to avoid the open/close operation for each processed file.