NorrinRadd
NorrinRadd

Reputation: 565

How to run batch file from "sent to " folder on network drive without “UNC path are not supported” message?

First of, I know that there are a few similar questions on this site already. I have read them, but none solved my problem.

Here is what I want to do. I want to place a small .bat script in my "send to" folder so I can execute it via the right click menu. Specifically I want to right-click on a specific folder and my scanner should save a file in this directory. The software I use for this is called naps2.

I use this script:

cd /d %1
@ echo off

SET fname=""
echo.%fname%
SET /P fname=Please enter the filename (no sapces!):

if NOT fname=="" (
        SET fname=%fname: =_%

  )

if  %fname%=="" (

    echo "No filename entered, using current date info instead."
    naps2.console -o "new_scan_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.pdf"

) else (
    echo.%fname%    
    naps2.console -o %fname%".pdf"
  )

echo scan complete!

Timeout 2  

It works fine as long as I run it on a local folder. It used to work on the network drive, but now it doesn't any more.

In this instance I get this error message:

CMD.EXE wurde mit dem oben angegebenen Pfad als aktuellem Verzeichnis gestartet.
UNC-Pfade werden nicht unterstützt.
Stattdessen wird das Windows-Verzeichnis als aktuelles Verzeichnis gesetzt.

The folder in question is actually mapped via Map network drive to a drive letter.

In this link there is a hint to "load the network share as if it's loaded from one of your local drives". I guess that means the same thing.

Is there anything I can do to make my script work independently on any of these settings in all cases? (i.e. on my local drives and on the network drives)

Upvotes: 1

Views: 1288

Answers (1)

wasif
wasif

Reputation: 15518

Change the cd /d %1 statement to pushd "%~1" then it will work fine. Because cd can work on local paths only, not on UNC paths.

Upvotes: 2

Related Questions