Home > Software engineering >  Batch Scripting Search .Txt files
Batch Scripting Search .Txt files

Time:12-05

I have 1 TB of .txt files with metadata content. The first column indicates the name of the file. The goal is to get all .txt files inside the directory C:\Textfiles\Docs and append the new file path inside every .txt file, like this D:\Docs\textfile1.txt with its filename.

Is there way to create a batch script to fulfil this?

Original .txt file (location drive C:

filename | data1 | data2 | data3

Output (and pastes in new location in drive D:

D:\Docs\filename | data1 | data2 | data3

Here is my attempt:

@echo off
setlocal enabledelayedexpansion
for %%a in (*.txt) do (
    set found=false
    If "!found! " == "false" (
      COPY "D:\Docs\" > file1.txt Set found =true
 )
)

CodePudding user response:

Your question is pretty incomplete, but anyway here it is a Batch file that may work:

@echo off

cd "C:\Textfiles\Docs"
for %%f in (*.txt) do (
   (for /F "usebackq tokens=1* delims=|" %%a in ("%%f") do (
      echo D:\Docs\%%f ^|%%b
   )) > "D:\Docs\%%f"
)

Please, do NOT reply a comment that just indicate: "this code don't work". Instead, review what is the detail in your real data that you don't posted that cause that the output be wrong and carefully describe what changes would be needed in the code in order to fix it... :/

  • Related