Fixed Using %~dp1 for paths with unavailable drives

Feb 12, 2009
4
0
In writing a function to parse arbitrary paths, I'm encountering an error for paths with drives which are unavailable (such as a path on a disconnected network drive).

An example of the function is:

:FN
setlocal
set p=%~dp1
...
goto :EOF

All variations on "%~dp1" and trying to use an expression based on %@full[%1] cause errors:

TCC: (Sys) The system cannot find the drive specified.
"X:"

This looks like a parsing error as I can only suppress it using a command group (eg, enclosing parenthesis).

CMD.exe works correctly, without complaint, but I want the function to work with TCC as well.

Is this a bug? Any suggestions on a work-around to avoid the pre-parsing?

Thanks, in advance.

- Roy
 
Feb 12, 2009
4
0
WAD = works as designed?

Not to be argumentative, but I've tested this and CMD _doesn't_ error _or_ "mysteriously fail". It correctly parses the string whether the drive exists or not. I have test calls with arbitrary paths that prove it.

And so, the question still stands... I can parse an arbitrary string into drive letter, path, name, extension with CMD, but have almost unsuppressable errors with TCC. I am amenable to special coding for TCC in the subroutine, if necessary. Do you have any way to parse an arbitrary path for the noted pieces, without emitting spurious errors?
 
Feb 12, 2009
4
0
I've attached a BAT test file which demonstrates that CMD works, and produces correct results, with arbitrary paths, whether the drive/path/file exists or not. Executing the same BAT with TCC fails with loud, difficult to suppress, error messages.

Any ideas/suggestions how to fix this?
 

Attachments

  • t-dir_of.bat
    8.4 KB · Views: 104

rconn

Administrator
Staff member
May 14, 2008
12,356
150
WAD = works as designed?

Yes.

Not to be argumentative, but I've tested this and CMD _doesn't_ error _or_ "mysteriously fail". It correctly parses the string whether the drive exists or not. I have test calls with arbitrary paths that prove it.

CMD parses the string; it just fails mysteriously when you actually try to *use* it somewhere. If the drive doesn't exist when you're parsing the string, it probably still doesn't exist when you're trying to use the string.

And so, the question still stands... I can parse an arbitrary string into drive letter, path, name, extension with CMD, but have almost unsuppressable errors with TCC. I am amenable to special coding for TCC in the subroutine, if necessary. Do you have any way to parse an arbitrary path for the noted pieces, without emitting spurious errors?

There's no way to tell TCC to pretend that a nonexistent drive might exist at some future time. You can use @ready[] to see if a drive is actually available.
 

samintz

Scott Mintz
May 20, 2008
1,503
16
Solon, OH, USA
I'm not sure if this is what you are looking for:
[R:\] dir i:

TCC: (Sys) The device is not ready.
"I:\"

[R:\] echo %@filename[I:\foo\bar.bat]
bar.bat

[R:\] echo %@path[I:\foo\bar.bat]
I:\foo\

-Scott
 
  • Like
Reactions: RoyIvyIII
Feb 12, 2009
4
0
CMD parses the string; it just fails mysteriously when you actually try to *use* it somewhere. If the drive doesn't exist when you're parsing the string, it probably still doesn't exist when you're trying to use the string.

I appreciate that you've taken the time to read my question and respond. But, that's incorrect. It is very possible that a location could be accessible at a later time, both during the execution of the script ("net use ...") or at a later time if the results are saved in the environment or registry.

And if the results are used appropriately (eg, using "IF EXIST ..." gates or simply using the PATH components for some other reason), there is no "mysterious fail". Any result is simply a string to be used (or misused) just like any other.

There's no way to tell TCC to pretend that a nonexistent drive might exist at some future time. You can use @ready[] to see if a drive is actually available.

@ready[] is too blunt an instrument to help as it returns false even for drives that will execute @full[] without errors (eg, BD/DVD/CD-ROM drives without media).

[R:\] echo %@path[I:\foo\bar.bat]
I:\foo\

@samintz, Thanks for the serious reply. I'd tried that method, and while it avoids the TCC parsing error messages, it doesn't have exactly the same semantics as the standard parameter options. Specifically, it fails to parse and fixup "." and ".." within the paths (the standard parameter options do this internal parse/fixup).

Ultimately, I have solved this by noting when TCC is the script parser, pre-parsing the argument string in those instances (pulling off the drive, if any, and changing it to the current drive), and then concatenating the original drive with the result. This strategy avoids all TCC errors and gives me correct results, which are equivalent whether using TCC or CMD.

- Roy
 
Similar threads
Thread starter Title Forum Replies Date
Jesse Heines Using Regular Expressions with the REN commanc Support 8
R WAD Unusable state when using Chinese characters Support 3
Joe Caverly Using TYPE with non-English text Support 22
L Using TCC.exe through an SSH connection Support 3
Joe Caverly Using @PSHELL from @EVAL Support 8
Jay Sage Command Will Not Run Using Short Name of Path Support 5
Jay Sage Cannot Postion Cursor in Command Line Using Mouse Support 7
MikeBaas Using the debugger Support 2
Joe Caverly Multiple Text Searches at once using FFIND or TPIPE Support 4
Dick Johnson Using the @instr function Support 5
Joe Caverly Using this CMD technique from TCC Support 17
Joe Caverly What version and Windows OS are you using? Support 3
Craig Fitzgerald Problems using tcstart.btm Support 3
R How to? Append files in multiple subfolders using copy? Support 8
M Ctrl-C when using command line history does nothing Support 2
Joe Caverly Using a Directory Alias with @iniwrite fails Support 14
C French accents using msgbox Support 4
C "Failed to update the system registry. Please try using REGEDIT" Support 3
x13 Problem listing repository files using DIR http(s)://... Support 8
R Regex using ^ Support 2
cxxl WAD Mouse movement sluggish when using TCC list Support 3
jfalch WAD internal "which" should check for FILEEXIST when using AppPaths entry Support 8
D How to? Scale font in TCC using wheel mouse or other means Support 2
fpefpe Documentation copy/move using /c or /u Support 2
gschizas Fixed Using codepage 65001 (UTF-8) breaks non-ASCII characters Support 8
D How to? Use typed envars using regex. Support 3
epement Using "everything" Support 10
U Installing the Compaq Visual Fortran 6.0 compiler using Take Command Support 8
Alexander WAD The number of files and dirs are multiplied when using multiple wildcards Support 6
T using bottom line for status bar Support 3
A How to? How do you launch TCC/LE using the already-open instance? Support 5
rps Fixed Using last argument variable ! Support 5
M Incorrect ARGV1 when using linux-style paths Support 4
D How to? Using a custom ini file with TCC from Take Command Support 7
thedave WAD Unable to type various characters using Windows 8's onscreen keyboard Support 7
D Documentation Using "send all input to other tabs" Support 11
Joe Caverly Word Count using TPIPE Support 10
Phileosophos Fixed Option Dialog Hangs when Using Help Support 7
MickeyF problem using COM object in VBScript from v16 x64 TCC but not from v15 32-bit TCC Support 4
S How to? How do I distinguish missing source file from download error when using HTTP? Support 6
Jay Sage Using EVERYTHING Command in TCMD15 Support 5
Charles Dye Odd behavior after using OPTION "Advanced" tab Support 2
T How to? Using FOLDERMONITOR 1 event causes multiple trigger(ing)s Support 8
samintz WAD FILEWRITE using SMOPEN Support 1
ehab aboudaya How to? 2 GUI questions and return HWND using TakeCommandIPC Support 3
C Using dif. sending addresses with sendmail Support 11
R TC 13 / Using TCDIALOG to exit commands Support 4
epement Video tutorials of using Take Command Support 2
electrotype Error using TCC: "Label not found" Support 6
Phileosophos unzip not using specified path Support 5

Similar threads