Search code examples
windowsbashfilebatch-fileevernote

I'm looking for a batch script that appends the names of multiple text files to the first line of each file


I have a folder that contains more than 200 text file (.txt)

I want an easy way to add each file name to the first line of each file.

example I have a file called "I am a file.txt" with the following content:

"
I am line one
I am line two
"

this should become something like this:

"
I am a file
=====
I am line one
I am line two
"

I'm wondering if someone could help me build a batch script that does that.

the reason for that is I want to upload all my text files to Evernote. But Evernote doesn't read the file name, instead it name the note as the first line in the text.


Solution

  • That worked for me:

    (just past this in a file called whatever.bat and run it)

    @echo off
    for /f "eol=: delims=" %%F IN ('dir /b /s "C:\Users\MyPC\Desktop\myDir\*.txt"') do (
      (
        echo %%~nF
        echo ___________________________
        type "%%F"
      )>"%%F.new"
      move /y "%%F.new" "%%F"
    )
    
    pause