Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 558 Vote(s) - 3.57 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Set variable to result of "Find" in batch-file

#1
I would like to set a variable based on the number of lines in a file that contain a give string.

Something like:

set isComplete = 0
%isComplete% = find /c /i "Transfer Complete" "C:\ftp.LOG"
IF %isComplete% > 0 ECHO "Success" ELSE ECHO "Failure"

Or:

set isComplete = 0
find /c /i "Transfer Complete" "C:\ftp.LOG" | %isComplete%
IF %isComplete% > 0 ECHO "Success" ELSE ECHO "Failure"

Neither of those options work, obviously.

Thanks.
Reply

#2
from the command line

for /f "tokens=3" %f in ('find /c /i "Transfer Complete" "C:\ftp.LOG"') do set isComplete=%f

from the batch script

for /f "tokens=3" %%f in ('find /c /i "Transfer Complete" "C:\ftp.LOG"') do set isComplete=%%f

Reply

#3
You don't need to use the `for` command; `find` will set the `ERRORLEVEL` to one of these values, based on the result:

- 0, At least one match was found.
- 1, no matches were found.
- 2 or more, an error occurred.

Since it looks like you just want to see if the transfer completed, and not the total count of times the string appears, you can do something like this:

@echo OFF

@find /c /i "Transfer Complete" "C:\test path\ftp.LOG" > NUL
if %ERRORLEVEL% EQU 0 (
@echo Success
) else (
@echo Failure
)
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through