Need some file check and variable set help.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Exouxas
Posts: 34
Joined: 01 Sep 2011 12:52

Need some file check and variable set help.

#1 Post by Exouxas » 01 Sep 2011 13:15

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%
...

Exouxas
Posts: 34
Joined: 01 Sep 2011 12:52

Re: Need some file check and variable set help.

#2 Post by Exouxas » 01 Sep 2011 13:19

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.

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: Need some file check and variable set help.

#3 Post by trebor68 » 02 Sep 2011 12:11

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.

Post Reply