# Batch file to read from a network text file



## DoeJohn (Sep 23, 2011)

I have a text file located at \\thedrive\a folder\another folder\log.txt. This file contains several lines of this kind of data "jdoe upgraded 09-20-2011 13:42:49.62". 
I have a batch file located "d:\folderName" that needs to read the "log.txt" file and obtain the local computer user username if it is in the file. If it is not in the file then a file is to be copied to the d drive from \\thedrive\a folder\another folder\ to "d:\folderName" and then run the file. This is what I currently have
@Echo Off
SetLocal EnableDelayedExpansion
::This line is just in case n has been defined before the batch file is run
Set n=
Set _InputFile="\\thedrive\a folder\another folder\log.txt"
For /F "tokens=*" %%I IN (%_InputFile%) DO (
Set /a n+=1
Set _var!n!=%%I
)
but the log file is not read. If I move the "log.txt" off the network it works just fine. I cannot move the "log.txt" file as other processes use it nor can I copy it.


----------



## Squashman (Apr 4, 2003)

Because you have Quotes around your file name you need to use the USEBACKQ option.

Please use CODE tags when posting code.

```
@Echo Off
SetLocal EnableDelayedExpansion
::This line is just in case n has been defined before the batch file is run
Set n=
Set _InputFile="\\thedrive\a folder\another folder\log.txt"
For /F "usebackq tokens=*" %%I IN (%_InputFile%) DO (
Set /a n+=1
Set _var!n!=%%I
)
```


----------

