Execute commands with notepad++ - command

How can I specify the actual file to process using the Run command in Notepad++.
I want for example run pdflatex using the actualfile as input, or the cs compiler, etc.
Using the entire path isn't practical, it must works with any actual file.

You can automatically add the current file using a variable in the execution string:
C:\temp\test.exe "$(FULL_CURRENT_PATH)"
The list of available variables is documented here. Examples:
FULL_CURRENT_PATH = E:\My Web\main\welcome.html
CURRENT_DIRECTORY = E:\My Web\main
FILE_NAME = welcome.html
NAME_PART = welcome
EXT_PART = .html
SYS.<var> e.g.: SYS.PATH = %PATH%
CURRENT_WORD = <selection or word under cursor>
CURRENT_LINESTR = <text of the line line under cursor>
CURRENT_LINE = <line number>
CURRENT_COLUMN = <column number>
NPP_DIRECTORY = c:\Program Files\notepad++
NPP_FULL_FILE_PATH = c:\Program Files\notepad++\notepad++.exe
You can also see the source code at RunDlg.cpp line 77 and line 26

Related

Faster copyfiles Matlab

I have a folder origin_training with subfolders like FM, folder1, folder2, ... . I can get the list of image files in .png format into a cell called FM.
FM_dir = fullfile(origin_training, 'FM');
FM = struct2cell(dir(fullfile(FM_dir, '*.png')))';
My goal is to match the names in my folder with the images in my cd, and make a new folder FM with the images from cd. Image names in the two paths are identical. I can do that with:
% mother_folder = '...' my current directory
filenames = FM(:,1);
destination = fullfile(mother_folder, 'FM', FM(:,1));
cellfun(#copyfile,filenames, destination);
This is really slow. Takes minutes even for small amounts of images (~30).
My current directory has ~ 10000 images (the ones that correspond to FM, folder2, folder3, ...). What am I missing here?
An alternative would be to create a shell command and execute it. Assuming FM contains full paths for each file, or relative paths from the current directory, then:
FM_dir = fullfile(origin_training, 'FM');
destination = fullfile(mother_folder, 'FM');
curdir = cd(FM_dir);
FM = dir('*.png');
cmd = ['cp ', sprintf('%s ',FM.name), destination];
system(cmd);
cd(curdir);
If you're on Windows, replace 'cp' by 'copy'.
Note that here we're not creating a shell command per file to be copied (presumably what copyfile does), but a single shell command that copies all files at once. We're also not specifying the name for each copied file, we specify the names of the files to be copied and where to copy them to.
Note also that for this to work, mother_folder must be an absolute path.
I somehow put my code into a function and now it works at expected speed. I suspected that cd had to do with the low speed so I am only passing the full directories as character vectors.
The same approach works for my purpose or with a slight modification to just copy from A to B. As now, it works to match files in A to those on B and copy to B/folder_name
function [out] = my_copyfiles(origin_dir, folder_name, dest_dir, extension)
new_dir = fullfile(origin_dir, folder_name);
% Get a cell with filenames in the origin_dir/folder_name
% Mind transposing to have them in the rows
NEW = struct2cell(dir(fullfile(new_dir, extension)))';
dest_folder = fullfile(dest_dir, folder_name);
% disp(dest_folder)
if ~exist(dest_folder, 'dir')
mkdir(dest_folder)
end
%% CAUTION, This is the step
% Use names from NEW to generate fullnames in dest_dir that would match
filenames = fullfile(dest_dir, NEW(:,1));
destination = fullfile(dest_folder, NEW(:,1));
% if you wanted from origin, instead run
% filenames = fullfile(new_dir, NEW(:,1));
% make the copies
cellfun(#copyfile,filenames, destination);
%Save the call
out.originDir = new_dir;
out.copyFrom = dest_dir;
out.to = dest_folder;
out.filenames = filenames;
out.destination = destination;
end

Octave: Problems with load

I'm currently doing a program in Octave where I want the user to be able to insert the file that he wants to load. The files in question are .mat files and are loaded with
load ("filename.mat")
I was thinking about doing something like this:
file=input("Whats the file name: ")
load ("file")
But that didn't work...
Anyone got any tips?
That's likely because you need to input the file name enclosed in single quotation marks : 'filename'. (Note: I use MATLAB but that should work just the same in Octave).
As an alternative you can use inputdlg to request user input. It gives you much flexibility as you can add fields to the prompt such as the file extension or else.
Here is a simple example:
clear
clc
prompt = {'Enter file name'};
dlg_title = 'Input';
num_lines = 1;
def = {'Dummy file'};
answer = inputdlg(prompt,dlg_title,num_lines,def)
The prompt looks like this:
You can fetch the asnwer like so:
name = answer{1};
And finally add the extension to load the .mat file:
filename = strcat(name,'.mat')
S = load(filename)
To do it in one go with the file extension:
prompt = {'Enter file name'; 'Enter file extension'};
dlg_title = 'Input';
num_lines = 1;
def = {'Dummy file'; '.mat'};
answer = inputdlg(prompt,dlg_title,num_lines,def)
name = answer{1};
extension = answer{2};
filename = strcat(name,extension)
S = load(filename)
Hope that helps!
I used Benoit_11's method but changed it to input instead since inputdlg doesn't seem to work in Octave.
clear
clc
name=input('Enter the file name, without the file extension: ','s')
filename = strcat(name,'.mat')
S = load(filename)

MATLAB dir command not working properly

I have a folder containing 9 .htk files. I need to use "dir", and then "readhtk" in a loop to import them to MATLAB, but DIR appears to give 10 files instead of 9! here is my code:
htkfiles = dir('/Users/Desktop/Acsegment/mfcdir/*.htk');
nhtkfiles = length(htkfiles); % 10!!! It should be 9 tough!
data = cell(nhtkfiles,2);
for k = 1:nhtkfiles
b(k,1) = strcat({'/Users/Desktop/Acsegment/mfcdir/'},{htkfiles(k,1).name});
eval(['data{k,1} = readhtk(b{k,1});']);
end
When looking at the filenames in htkfiles, I have them like this:
htkfiles(1,1).name = '.htk'
htkfiles(2,1).name = 'fadg0_si1279.htk'
htkfiles(3,1).name = 'fadg0_si1909.htk'
htkfiles(4,1).name = 'fadg0_si649.htk'
htkfiles(5,1).name = 'fadg0_sx109.htk'
htkfiles(6,1).name = 'fadg0_sx19.htk'
htkfiles(7,1).name = 'fadg0_sx199.htk'
htkfiles(8,1).name = 'fadg0_sx289.htk'
htkfiles(9,1).name = 'fadg0_sx379.htk'
htkfiles(10,1).name = 'faks0_si943.htk'
Comparing to what I see in that folder, the first file is not supposed to be there! Anyone got any ideas why Im getting one extra file?
As mentioned in the comments: the dir command actually works properly, there just happens to be a hidden file.
These files starting with a dot could be removed from your list like so:
d=dir;
d(strncmp({d.name},'.',1))=[];

Alternative to command line for short path names

There is a specific case where having "path with space" doesn't work and I need to get the Windows short path names (e.g. Program Files = Progra~1 and Program Files (x86) = Progra~2).
Here what I'm doing for now :
[status, PATHROOT] = dos([ ...
'for %A in ("' ...
myPathWithSpace ...
'") do #echo %~sA' ...
]);
Now, I tried using regexp and regexprep to format the file path, but it fails in some case to reproduce the dos short names. So how can I reproduce the dos command with MATLAB commands?
And here my ugly try with regexp and regexprep:
PATHROOT = regexprep(regexprep(regexp(myPathWithSpace,'\w:\\\w*\s\w*\\.*','match'),'\s', ''),'(\w:\\\w{6})\w*','$1~1');
Use this function:
function shortPath = getshortpath(longPath)
fs = actxserver('Scripting.FileSystemObject');
shortPath = fs.GetFolder(longPath).ShortPath;
fs.delete;

How to insert entire file path into text box, not just filename? Access 2010

I am currently using the following code to select a file and add its path to a text box.
Dim objDialog As Object
Set objDialog = Application.FileDialog(3)
With objDialog
.AllowMultiSelect = False
.Show
If .SelectedItems.Count = 0 Then
MsgBox "No file selected."
Else
Me.FileNameTextBox = Dir(.SelectedItems(1))
End If
End With
Set objDialog = Nothing
How do I make it so the entire file path is inserted, not just the file name?
.SelectedItems(n) already contains the full path and filename. If what you need is just to separate the name of the file from its path, instead of using the Dir function you could use something like this:
Me.FileNameTextBox = Mid$(.SelectedItems(1), InStrRev(.SelectedItems(1), "\") + 1)
Me.PathTextBox = Left$(.SelectedItems(1), InStrRev(.SelectedItems(1), "\"))
Hope this helps!
you need to remove the dir() part, EG....
Me.FileNameTextBox = .SelectedItems(1)