Computing.Net > Forums > Disk Operating System > Find username in txt and goto end

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Find username in txt and goto end

Reply to Message Icon

Name: joe smith
Date: August 21, 2003 at 11:51:53 Pacific
OS: Win2k Pro
CPU/Ram: 933/256
Comment:

I need to check a textfile on a server from a logon script for %username% and if it exist I want to goto the end of script.

I have tried with the find command, but not sure what to do after I tell it to find the username.

This is a line I tried, but not sure how to tell it to goto end if it finds the string:

Find /I "%USERNAME%" \\server\shares\sample.txt

I tried to do: If errorlevel 0 goto End, but not working. I am pretty much a rookie at this and don't know how to use variables much. Any help would be greatly appreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: lode
Date: August 21, 2003 at 12:11:23 Pacific
Reply:

I think you need to drop FIND and use IF EXIST instead, for example:

IF EXIST %username% GOTO END
GOTO SKIP
:SKIP
REM the part of script to skip
GOTO END
:END
REM goes here if %username% exists
REM otherwise goes through SKIP

The GOTO after IF EXIST will skip right to END if true.

You may also want to put COMMAND/F/C in front of IF EXIST to pass any errors:


0

Response Number 2
Name: joe smith
Date: August 21, 2003 at 13:55:26 Pacific
Reply:

Hey, thanks for the response. This is what I tried, but it doesn't goto end. It just keeps running.
if exist %username% \\server\shares\sample.txt goto End

Thanks for any help.


0

Response Number 3
Name: lode
Date: August 22, 2003 at 18:56:25 Pacific
Reply:

Well, I'm not sure, but I think what you should try it to pipe the if exist from the find command like this:

Find /I "%USERNAME%" [path] ¦ If Exist %USERNAME% Goto End
:End

The pipe ¦ symbol takes what was obtained from the first command, and passes it to the second command. That's the theory, but I'm not too sure if it would work. Some commands don't work when piped.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Find username in txt and goto end

how to find OS in batch file www.computing.net/answers/dos/how-to-find-os-in-batch-file/11085.html

DOS Registry Program www.computing.net/answers/dos/dos-registry-program/7062.html

Frustrated With Batch -- Set= www.computing.net/answers/dos/frustrated-with-batch-set/4804.html