1

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)

Compo
  • 36,585
  • 5
  • 27
  • 39
NorrinRadd
  • 545
  • 6
  • 21
  • I cannot understand why you're getting a UNC error when you've told us that the path is mapped to a drive letter. A UNC file path is composed like this `\\\\` and a mapped drive like this `:\\`. I also note that among the answers you linked to, there was one which suggested using `PushD` and/or `PopD`, what happened when you tried that instead of `CD /D`? – Compo Dec 11 '19 at 15:05
  • It would also help us if you were to provide the command / invoke method that you're running from 'send to' entry. – Compo Dec 11 '19 at 15:12

1 Answers1

2

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.

Wasif
  • 14,755
  • 3
  • 14
  • 34
  • Wasif Hasan, that option appears in more than one of the answers within their provided link. The OP stated that they've 'read' them and 'none solved my problem'. Additionally, they've stated that the network path is already mapped to a drive letter, and my comment asks them what happened when they tried it. I would therefore suggest that your answer has been offered with little regard to what had been mentioned at the time of its submission. – Compo Dec 11 '19 at 16:05
  • I actually tired this but i still initially get the message that the script was started from an current folder with UNC adress and the Windir directory is used instead. I aborted at this stage....mea culpa However , if i let the script run it actually works despite the error message? – NorrinRadd Dec 12 '19 at 07:32
  • I admit i do noit really understand these commands either. Can someone direty me were to actually find the meaning of the /d %1 resp. "%~1 part of the commands? I know that %1 is used to represent a variable or matched string but what is actually passed into it? – NorrinRadd Dec 12 '19 at 07:42
  • `"%~1"` is used to remove the leading and trailing quotes and wrap them by external double quotes. It is given for safety because if you try to pass an argument without quotes containing space it will create trouble. – Wasif Dec 12 '19 at 08:09