madkat (madkatsjournal) wrote in batch_scripting,
madkat
madkatsjournal
batch_scripting

Batch script location awareness?

I just wrote this quick code snippet..

@ECHO OFF
PUSHD\
CD |SET /p DRIVE=
ECHO You are on Drive %DRIVE%
POPD


When run from any named drive, using the command line, it outputs:
You are on Drive x

where x is the drive letter.

Unfortunately it won't run from a batch script. And even more unfortunately, batch scripts run from UNC paths hurl themselves back to C:\Windows before they start.

Does anyone know of a way of detecting whether a batch script was started from a UNC path, and what that path was?

Another useful item would be whether the current drive is read-only...?
  • Post a new comment

    Error

    default userpic
  • 0 comments