Page 1 of 1

Need some file check and variable set help.

Posted: 01 Sep 2011 13:15
by Exouxas
Hi!

Okay, this is my problem:

I want a batch file to check a folder for files, then put (if its a text file) the contents in a variable eg. set variable1=%content_of_file1% or more specific the second line. And it continues like this:

set variable2=%content_of_file2%
set variable3=%content_of_file3%
set variable4=%content_of_file4%
...

Re: Need some file check and variable set help.

Posted: 01 Sep 2011 13:19
by Exouxas
Would also like if the batch file could tell which number is biggest out of a bunch of numbers eg. 1 4 7 9. and it would tell me that 9 is the biggest number.

Re: Need some file check and variable set help.

Posted: 02 Sep 2011 12:11
by trebor68
Here a simple solution:

Code: Select all

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set num=0
for /f %%d in (datfile.txt) do if exist %%d (
  set /a num+=1
  set filename_!num!=%%d
)
echo There are !num! files exist from the list.
pause


You only have access to the variables as long as the batch runs.