1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: BACTH question, I NEED HELP PEASE.

Discussion in 'Software Development' started by g_01001, Sep 22, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. g_01001

    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.
     
  2. -Fabez-

    -Fabez-

    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.
     
  3. dtech10

    dtech10

    Joined:
    Jan 31, 2003
    Messages:
    53
    Hi g_01001

    Whats in filecount.txt.
     
  4. g_01001

    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.!!!
     
  5. -Fabez-

    -Fabez-

    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 ?
     
  6. g_01001

    g_01001 Thread Starter

    Joined:
    Sep 22, 2008
    Messages:
    11
    Yes, that is what I need to do.

    Thanks
     
  7. TheOutcaste

    TheOutcaste

    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
     
  8. g_01001

    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 =)
     
  9. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/752300

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice