0

I have a file name.txt that contains the ff: code

for /f "tokens=1" %%s in (C:\user\files\title.txt) do (
log normal "c:\user\user-log.txt"
)

Now I have a batch file that calls names.txt. However, it always shows

The system cannot find the file specified.

How to solve this issue?Is it possible to have a batch code on a text file?

PeterS
  • 724
  • 2
  • 15
  • 31
  • You can have batch code in txt but dont expect to execute it as you are running the batch file. By the way how you are executing it when you have above error ? Also what are you trying to achieve ? – Sariq Shaikh Dec 12 '14 at 19:26
  • @Shaikh Mohammed Shariq Im am using a batch file that calls specific variable where the location of name.txt was stored (set varBCscript=@C:\user\userfiles\name.txt) – PeterS Dec 12 '14 at 19:28
  • Can you please post the code of your batch file which calls above variable ? Also can you double check that the file path is correct and the file is available at the same location described above ? – Sariq Shaikh Dec 12 '14 at 19:31
  • @Shaikh Mohammed Shariq BTW, do we have any option where in we can pass the content of a file into another text file? for example I have name.txt where one value must get from another text file. I only need to get the first line from another text file. – PeterS Dec 12 '14 at 19:34
  • Yes you can read the text file data and also pass it in another file through batch file itself. Can you please elaborate what exactly you are trying to achieve so that we can work in that direction ? – Sariq Shaikh Dec 12 '14 at 19:38
  • For example the content of my name.txt file is to display the content of file1.txt. How can we achieve this in txt file? – PeterS Dec 12 '14 at 19:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/66780/discussion-between-shaikh-mohammed-shariq-and-peters). – Sariq Shaikh Dec 12 '14 at 19:51

1 Answers1

0

As discussed you want to read a file and append read content into another file. For that you can use below script created based on answers from these posts

Reading a text file line by line and storing it in an array using batch script

Append text with .bat

@echo off
set "file=F:\FileToReadFrom.txt"
set /A i=0

for /F "usebackq delims=" %%a in ("%file%") do (
set /A i+=1

call set array[%%i%%]=%%a
call set n=%%i%%
)

for /L %%i in (1,1,%n%) do call echo %%array[%%i]%%>> F:\AppendToFile.txt

Above code you need to put in batch file also you need to replace your path for FileToReadFrom.txt and AppendToFile.txt as per your requirement.

Let me know if this is not what you were looking for.

Community
  • 1
  • 1
Sariq Shaikh
  • 940
  • 8
  • 29