Solved: BACTH question, I NEED HELP PEASE.

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

g_01001

Thread Starter
Joined
Sep 22, 2008
Messages
11
Hi new in this forum and also new at programming in batch. What I need is to assign the results of a search to a variable so that later that result is show in a message in the screen if that number(search result) is bigger than 1.

The search is this, and so far shows the number of files in some directory and shows that in a txt file(filecount.txt):

dir /A-D/B/O/-P/N D:\batch\GBLCRMCDC421A*.xls |find /v /c /i "D:\batch\" >D:\ztest\filecount.txt
::What I need is to assign the results of this search to a %VAR%

IF NOT(%VAR% )==(1) GOTO showmessage

:showmessage

echo. WARNING! - More than 2 files with the name GBLCRMCDC421A*.xls, were found, cant is %VAR%

Thanks.
and English is not may first language. Regards.
 
Joined
Jul 28, 2008
Messages
1,899
Try using a higher level language as it will be much easier and will run faster than batch. If you want I can help you with the code, but I do not realy understand your explantion of what you want your program to do.
 

g_01001

Thread Starter
Joined
Sep 22, 2008
Messages
11
Thanks a lot for respond and sorry if I was not clear about my problem.
The thing is that I can't use another language to do this, it has to be a batch because later on it will be use by a command (in cmd)

Here is the full description:
In some directory (for example D:\FIlesToSearch\) are several files whit the same file extension and 2 class of mask to identify them (this is one of them: GBLCRMCDC421c*.*.xls)
The '*' means that to the static name of the file is added on some others chars like 'ADS45U'. So what is required to do is to count the total of files with certain mask(like GBLCRMCDC421c*.*.xls) in one specific directory;
And the result of that search (that should be a number) must be assigned to a variable, so I can ask that "when the count of files found is biger than 1, then show some warning in a log error and terminate the process"
The message is something like this: "Warning - There was found %cant% of files with the mask GBLCRMCDC421c*.*.xls" . The %cant% is where it should be the result of the search for the files.

This is the code to search for the cant of files, ('CountFile' is a txt file that keeps the results of the search, so actually doesn’t matter much. It is just used to see the number of files found in a .txt)
dir/A-D/B/O/-P/N D:\FIlesToSearch\GBLCRMCDC421c*.*.xls |find /v /c /i "D:\FIlesToSearch\" >>"%CountFile%"

What I need is to assign the results of this search to a variable (%cant% for example) so then I can use it in the "IF" statement.
IF NOT(%cant%)==(1) GOTO showmessage
:showmessage
echo. "Warning - There was found %cant% files with the mask GBLCRMCDC421c*.*.xls"

Well, that's all. Thanks again for your help. I’m a webie in this language so I don't know if my code (the search part) is the best way to do this.

Thanks A LOT for the help.!!!
 
Joined
Jul 28, 2008
Messages
1,899
Python will run from the command line and is easier to use. So to clarify, you want your program to search a directory for a file that has two wildcards and assign the number of found files to a variable ?
 
Joined
Aug 7, 2007
Messages
9,028
Welcome to TSG!

set /P cant=<filecount.txt

This will assign the first line of filecount.txt to the variable cant

If a found count of zero is OK, you may want to use this for the IF:
If %cant% GTR 1 Goto Showmessage

Your version will display an error if the count it finds is zero.

HTH

Jerry
 

g_01001

Thread Starter
Joined
Sep 22, 2008
Messages
11
HI!!

You really help me with this: set /P cant=<filecount.txt

My problem is solved. Thanks for your help =)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top