Help - Search - Members - Calendar
Full Version: command line check for file on remote system
ieXbeta Board > Tech > Developer Center
dkreifus
Is there a way to query for specific folder/file on a remote system?
I essentially want to do a IF EXIST command, on a remote system.
Taco Bell
Is doing a temporary "net use X: \\server\share" command okay to get a 'local' path to the file, dk?
DangerousDave86
IF EXIST "\\pc-name\sharedFolder\file name.ext" echo hello

Works on my home computer just fine, remember to use quotes with spaced filenames though.
If you can access the file in Windows Explorer using the path you should be able to check it exists in batch.
Taco Bell
Ah, I just presumed that failed to work DD86 based on dk's posting, so good to know.
dkreifus
yea..the command line parameters indicated it didn't exist. And it turns out some server guy had wrong permissions, which is why it didn't work when i tried.

Also, I don't think theres a way to specify permissions. But either way, the command works for the purpose.
XP_2600
Thanks guy for the info, but is there anyway to put if else?
DangerousDave86
Not really, best way to do it would be with GOTOs make the if else yourself
I would do it this way..
CODE
IF NOT expression GOTO :ELSE
    Code for TRUE
    ....
    ....
    GOTO :ENDIF
:ELSE
    Code for FALSE
    ....
    ....
:ENDIF


that creates the same layout as normal if/else. However it requires IF NOT instead of just IF to work. Hope you understand why.. the correct way to explain evades me.

The other way to do it would be as follows
CODE
IF expression GOTO :IF
IF NOT expression GOTO :ELSE
:IF
    TRUE Code
    ....
    ....
    GOTO :ENDIF
:ELSE
    FALSE Code
    ....
    ....
:ENDIF

just two ways of writing the same thing.. The 2nd might make more sense at first glance but the 1st is slicker..

Hope this helps smile.gif

Edit, a variation on the second would be:
CODE
IF expression GOTO :IF
GOTO :ELSE
:IF
    TRUE Code
    ....
    ....
    GOTO :ENDIF
:ELSE
    FALSE Code
    ....
    ....
:ENDIF
I think thats it for ideas now...
DangerousDave86
http://www.microsoft.com/resources/documen...s/en-us/if.mspx

looks like there is an ELSE in newer command line interpreters...
XP_2600
Yeah, thanks for the info.
Flogger
CODE
echo off

if EXIST P:filetest.txt GOTO :EOF

echo *
echo **********************************
echo **      CANNOT FIND FILE                      **
echo **********************************
echo *

PAUSE
echo on
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.