0

I have 6500 '.txt' files in a directory. The name of all files begin with the Unique ID, example below.

101101_ABCD.txt
101102_ABCD.txt
101103_ABCD.txt 

All these files have a text 'Success' or 'Failure' or any other character.

I want to copy the file name and its corresponding content in one file.

I have tried below command but, it gives only content.

copy *.txt New_File.txt

The above command gives below result in the New_File.txt

Success
Failure
Success

whereas I am looking for below result in New_File.txt

101101_ABCD.txt Success
101102_ABCD.txt Failure
101103_ABCD.txt Success
Stephan
  • 53,940
  • 10
  • 58
  • 91
Prafulla
  • 575
  • 1
  • 3
  • 21
  • The command __COPY__ copies contents of files. There is no possibility using this command to get the names of the source files also written into the destination file. You can use in the batch file `(for /F "tokens=1* delims=:" %%I in ('%SystemRoot%\System32\findstr.exe /C:Failure /C:Success *.txt') do echo %%I %%J)>New_File.txt`. `%%I` could be also modified to `%%~nI` to write into `New_File.txt` just the file names without file extension `.txt`. – Mofi Oct 09 '21 at 10:25
  • 1
    `findstr "Success Failure" *.txt >newfile.out`. Use another extension for the output file or put it in a different folder, else it will be processed too. – Stephan Oct 09 '21 at 10:25
  • 1
    @Prafulla I recommend to read [How to use OR operator with command FINDSTR from a Windows command prompt?](https://stackoverflow.com/a/32159911/3074564) It explains in detail my solution with using `/C:Failure /C:Success` and also Stephan's solution using `"Success Failure"` which result both in searching case-sensitive for the literal interpreted strings `Success` OR `Failure` in the files with file extension `.txt`. – Mofi Oct 09 '21 at 10:44

0 Answers0