Network path not working for xlswritefig in Matlab - vba

I am trying to open a workbook that is located on a network path using the function xlswritefig. I.e. the path does not start with the traditional letter such as C:\. Instead it looks as follows:
\\networkmain\folder\to
When I try to open the excel file on this folder in Matlab, I noticed that Excel adds the current path in front of the the path. I.e. if I am currently in folder
C:\Matlab\ then Excel tries to open:
C:\Matlab\networkmain\folder\to
How can I prevent this from happening and redirect to the network path?

The problem was with the function xlswritefig. To solve for this issue, step into the function and change the following line of code (line 86):
%**op = invoke(Excel.Workbooks, 'open', [pwd filesep filename]);
op = invoke(Excel.Workbooks, 'open', filename);
Thus remove the [pwd filesep] part.

I don't think UNC paths are supported in Matlab (at least the didn't use to). The simple way forward is to map your folder to a letter drive. It is possible to do this in Windows Explorer, but I tend to use net use in the command prompt. net help use will show you the syntax

UNC (network) paths are not supported by MATLAB. However, here is a workaround which sets (and unsets) a network drive letter using the system command.
% Execute system command to assign drive letter
system('net use Z: \\networkmain\folder\to');
% Perform actions under this drive
cd(Z:\);
% ...
% Unmount the drive
system('net use Z: /delete');
You could use some simple looping to find the next available drive letter, as the system call shoudn't override an existing drive letter.

Related

Check if Windows batch variable starts with a specific string

How can I find out (with Windows a batch command), if, for example, a variable starts with ABC?
I know that I can search for variables if I know the whole content (if "%variable%"=="abc"), but I want that it only looks after the beginning.
I also need it to find out where the batch file is located, so if there is a other command that reveals the file's location, please let me know.
Use the variable substring syntax:
IF "%variable:~0,3%"=="ABC" [...]
If you need the path to the batch file without the batch file name, you can use the variable:
%~dp0
Syntax for this is explained in the help for the for command, although this variable syntax extends beyond just the for command syntax.
to find batch file location use %0 (gives full patch to current batch file) or %CD% variable which gives local directory

Execute scripts by relative path in Oracle SQL Developer

First, this question relates to Oracle SQL Developer 3.2, not SQL*Plus or iSQL, etc. I've done a bunch of searching but haven't found a straight answer.
I have several collections of scripts that I'm trying to automate (and btw, my SQL experience is pretty basic and mostly MS-based). The trouble I'm having is executing them by a relative path. for example, assume this setup:
scripts/A/runAll.sql
| /A1.sql
| /A2.sql
|
/B/runAll.sql
/B1.sql
/B2.sql
I would like to have a file scripts/runEverything.sql something like this:
##/A/runAll.sql
##/B/runAll.sql
scripts/A/runAll.sql:
##/A1.sql
##/A2.sql
where "##", I gather, means relative path in SQL*Plus.
I've fooled around with making variables but without much luck. I have been able to do something similar using '&1' and passing in the root directory. I.e.:
scripts/runEverything.sql:
#'&1/A/runAll.sql' '&1/A'
#'&1/B/runAll.sql' '&1/B'
and call it by executing this:
#'c:/.../scripts/runEverything.sql' 'c:/.../scripts'
But the problem here has been that B/runAll.sql gets called with the path: c:/.../scripts/A/B.
So, is it possible with SQL Developer to make nested calls, and how?
This approach has two components:
-Set-up the active SQL Developer worksheet's folder as the default directory.
-Open a driver script, e.g. runAll.sql, (which then changes the default directory to the active working directory), and use relative paths within the runAll.sql script to call sibling scripts.
Set-up your scripts default folder. On the SQL Developer toolbar, Use this navigation:
Tools > Preferences
In the preference dialog box, navigate to Database > Worksheet > Select default path to look for scripts.
Enter the default path to look for scripts as the active working directory:
"${file.dir}"
Create a script file and place all scripts associated in it:
runAll.sql
A1.sql
A2.sql
The content of runAll.sql would include:
#A1.sql;
#A2.sql;
To test this approach, in SQL Developer, click on File and navigate and open the script\runAll.sql file.
Next, select all (on the worksheet), and execute.
Through the act of navigating and opening the runAll.sql worksheet, the default file folder becomes "script".
I don't have access to SQL Developer right now so i can't experiment with the relative paths, but with the substitution variables I believe the problem you're seeing is that the positional variables (i.e. &1) are redefined by each start or #. So after your first #runAll, the parent script sees the same &1 that the last child saw, which now includes the /A.
You can avoid that by defining your own variable in the master script:
define path=&1
#'&path/A/runAll.sql' '&path/A'
#'&path/B/runAll.sql' '&path/B'
As long as runAll.sql, and anything that runs, does not also (re-define) path this should work, and you just need to choose a unique name if there is the risk of a clash.
Again I can't verify this but I'm sure I've done exactly this in the past...
you need to provide the path of the file as String , give the patch in double quote it will work
**
For Example
#"C:\Users\Arpan Saini\Zions R2\Reports Statements and Notices\Patch\08312017_Patch_16.2.3.17\DB Scripts\snsp.sql";
**
Execution of Sql
#yourPath\yourFileName.sql
How to pass parameters in file
#A1.sql; (Parameter)
#A2.sql; (Parameter)
This is not absolute or relative path issue. It's the SQL interpreter issue, where by default it will look for files which are having .sql extention.
Please make sure to modify the file name to file_name.sql
Ex: if workspace is having file name called "A", then move the file from A to "A.sql"

Matlab can't find member functions when directory changes. What can I do?

I have a Matlab program that does something like this
cd media;
for i =1:files
d(i).r = %some matlab file read command
d(i).process();
end
cd ..;
When I change to my "media" directory I can still access member properties (such as 'r'), but Matlab can't seem to find functions like process(). How is this problem solved? Is there some kind of global function pointer I can call? My current solution is to do 2 loops, but this is somewhat deeply chagrining.
There are two solutions:
don't change directories - instead give the file path the your file read command, e.g.
d(i).r = load(['media' filesep 'yourfilename.mat']);
or
add the directory containing your process() to the MATLAB path:
addpath('C:\YourObjectsFolder');
As mentioned by tdc, you can use
addpath(genpath('C:\YourObjectsFolder'));
if you also want to add all subdirectories to your path.
Jonas already mentioned addpath, but I usually use it in combination with genpath:
addpath(genpath('path_to_folder'));
which also adds all of the subdirectories of 'path_to_folder' as well.

Automatically locating a file

By default AutoCAD installs a text based file called acad2010.lsp at the set location below
Dim FILE_NAME As String = "C:\Program Files\AutoCAD 2010\Support\acad2010.lsp"
However it my be that the user/ administrator/ or third party has changed the location of this file. Is it possible to then locate it using the following
Dim FILE_NAME As String = "C:\*\acad2010.lsp"
In other words search the entire c:\ drive for file acad2010.lsp?
If this doesn't work can you please let me know what would?
You could search for it with an FSO. It's not going to be fast however you do it but this is the fastest way I can think of.
http://www.microbion.co.uk/developers/fso.htm should give you a rough idea of how it's done.
Your solution will not work. Is not possible to locate it using *. (BTW is possible in ms-builds scripts). The only way of doing it is:
1- Create a FindFile function (check for example
http://xlvba.3.forumer.com/index.php?showtopic=125)
2- Use it to locate the exact path of the file. (It could be really time
consuming)
3- From this point your code is the same...
Unfortunately, you can't use wildcards in a filepath. You have two options:
Prompt the user for the file location using the "Open File" dialog. The code to do this varies based on which Office product you are using. In Excel, you would use the Application.FindFile method (more info here).
Write your own function to search the filesystem for the file. Microsoft provides an example here.
If that file is used by internal functions of the application, the installer will have recorded a registry key for the file's location.
Open regedit.exe and search for the file name and path.
You can read a registry entry using this VBA one-liner:
CreateObject("WScript.Shell").RegRead(strRegPath)
You may need a terminating backslash on the key address, but that's a safe and simple registry access method. More details on the MSDN site:
https://msdn.microsoft.com/en-us/library/x05fawxd%28v=vs.84%29.aspx

How do I extend this batch command?

I came across this piece of batch code. It should find the path to every single .exe file if you enter it.
#Set Which=%~$PATH:1
#if "%Which%"=="" ( echo %1 not found in path ) else ( echo %Which% )
For instance, if you save this code in the file which.bat and then go to its directory in DOS, you can write
which notepad.exe
The result will be: C:\WINDOWS\System32\notepad.exe
But it's a bit limited in that it can't find other executables. I've done a bit of batch, but I don't see how I can edit this code so that it can crawl the hard drive and return the exact path.
When you want to find an executable (or other file) anywhere on the drive, not just in PATH, then perhaps only the following will work reliably:
dir /s /b \*%!~x1 | findstr "%1"
But still, it's horribly slow. And it doesn't work with cyclic directory structures. And it probably eats children.
You may be much better off using either Windows Search (dependin on OS) or writing a program from scratch which does exactly what you want (the cyclic dir thing might happen on recent Windows versions pretty easily; afaik they have that already by default).
Here's the same thing written in python:
import os
def which(program,additional_dirs=[]):
path = os.environ["PATH"]
path_components = path.split(":")
path_components.extend(additional_dirs)
for item in path_components:
location = os.path.join(item,program)
if os.path.exists(location):
return location
return None
If called with just an argument, this will only search the path. If called with two arguments ( the second being an array ), other directories will be searched.Here are some snippets :
# this will search notepad.exe in the PATH variable
print which("notepad.exe")
# this will search whatever.exe in PATH. If not found there,
# it will continue searching in the D:\ drive and in the Program Files
print which("whatever.exe",["D:/","C:/Program Files"])