Scriping and UNC paths

My Directory Opus scripts are failing when I browse a UNC folder paths.

For example this batch file script fails for a UNC path:

@runonce: Select DESELECTNOMATCH PATTERN *.log
@runonce: qgrep -B -i {allfilepath|filem} "#" >log_errors.txt
@runonce: qgrep -B -i {allfilepath|filem} "!" >log_warnings.txt

The problem is that the output redirect does not get sent to the source directory but some other folder instead (i can't remember if it was the Windows\System32 or my $HOME directory).

So I've come up with the following work-around. It runs the commands in a non-UNC folder then copies the output files back to the UNC path.

@runonce: Select DESELECTNOMATCH PATTERN *.log
@runonce: Delete QUIET NORECYCLE FILE C:\Temp\LogErrors*.txt
@runonce: C:
@runonce: cd C:\Temp\LogErrors
@runonce: qgrep -B -i {allfilepath|filem} "#" >log_errors.txt
@runonce: qgrep -B -i {allfilepath|filem} "!" >log_warnings.txt
@runonce: Copy FORCE FILE C:\Temp\LogErrors*.txt TO {sourcepath$}

I am not entirely satisfied with this solution. Does anyone have a better one? I am new to DOpus scripting so I may be doing something wrong. I hope so because I am a little dismayed that I having problems with my first DOpus script.

Windows does not let you set the current directory to a UNC path for command-line programs:

blogs.msdn.com/oldnewthing/archi ... 83851.aspx

Instead of relying on the current directory you should specify the full path to file you want to redirect qgrep's output to, like this:

qgrep -B -i {allfilepath|filem} "#" >{sourcepath$}\log_errors.txt

You don't need to use @runonce: for any of the lines in your script, by the way. That is only needed for lines which would be run per-file to force them to only run on the first file. If a line doesn't use any file paths, or uses all file paths at once, then it will only ever be run once.

Thanks Leo, that's a better solution. I assumed there was going to be a UNC limitation on the redirect, but it's only on the current working directory.

I don't think it is very good to have inconsistant behavior depending upon the type of paths you are browsing. Ideally Directory Opus scripts should run the same way on any type of folder.

For some reason my Copy command was trying to copy all files from the source folder to the source folder unless I added the @runonce. Looking at the documentation I can only assume this is the proper usage of the control code.

Did you read the page I linked? It's a Windows problem, not an Opus problem. What you're asking for would require Opus to either temporarily map a drive letter for commands (which would cause all kinds of problems with many programs) or to replace Windows itself.

With that exact command? I just tried it and it seems fine here. (Copies *.txt from the temp dir to the source dir and nothing else.)

Sorry, you're right, that copy line works fine without @runonce. I can't recall what I did to cause that original problem.

I did read the blog entry. It's actually not a Windows problem, but a problem with the standard command interpreter (CMD.exe). Opus is not forced to use it as their command shell.

Anyway, my main issue is with the scripts being fragile: it works for one folder but not another.

If you don't want Opus to use cmd.exe then don't tell it to make a DOS batch button.

Because you told Opus to make a DOS batch button and DOS batch buttons don't let you CD to UNC paths. That's not really Opus's fault.

If you don't want Opus to use cmd.exe then don't tell it to make a DOS batch button.
[/quote]

Fair enough, I'd rather not use DOS batch scripts if possible.

Can I run a command line tool as an external program and redirect the output? I think without redirection and pipe support that CMD offers the scripts are rather limited.

That depends on the command and whether it lets you specify an output file or always writes to stdout and expects something else to capture/redirect its output.