FolderBrowserDialog last Folder Name - string

I'm new to C++/CLI and have a Question about the FolderBrowserDialog function.
Using ->SelectedPath gives me "C:\Folder\Subfolder\Selected Folder"
How can I save JUST "Selected Folder" to a string?
FolderBrowserDialog^ DestinationFolderDialog;
DestinationFolderDialog = gcnew System::Windows::Forms::FolderBrowserDialog;
System::Windows::Forms::DialogResult result = DestinationFolderDialog->ShowDialog();
if (result == System::Windows::Forms::DialogResult::OK)
{
String^ path = DestinationFolderDialog->SelectedPath;
SetDestinationPath(path);
lblDestinationPath->Text = path;
}
The way I set my Destination Path
And now I want to work with it
String^ pathSource = GetSourcePath();
String^ pathDest = GetDestinationPath();
Im trying to generate Symlinks.
So im Selecting "Y:\Movies\Movie_a" as Source
And im Selecting "X:\" as Destination for my Symlink Folder
To Create it I need to add "Movie_a" to "X:\"
Can someone help me?

If what you want is to extract the last dir name from C:\Folder\Subfolder\Selected Folder then you can:
use Path.GetFileName method to acquire the last part from the path
call String.Split with the Path.PathSeparator and take the last array element
Updated in respect to #LucasTrzesniewski comment

Related

Node.JS - shell.mkdir() - Creates random file names instead of taking variable input

Good day all,
I've been working on a program for a few weeks now and I'm just come across an error where the filename is not taking the variable given to it. It is creating a random name (ex. 14DZ5I~5)
Here is the code used to create the folders:
if (body.folders){
// Create Parent Folder
var parentFolder = body.name.trim() + "/"
var fullPath = "DOWNLOAD/" + parentFolder
console.log(parentFolder)
for(item of body.folders){
console.log(item.name_with_path.trim())
var subFolder = "DOWNLOAD/" + item.name_with_path.trim()
shell.mkdir('-p', subFolder)
if(item.has_children_folders || item.has_children_files){
getFolderFile(PID=PID, FID=item.id, ParentFolder=parentFolder)
}
}
Please let me know your thoughts!
I found the answer to my question!
Seems like, on Windows systems, shell.mkdir doesn't like files that end in " " (whitespace). Some strings being fed to the loop ended in " " so I used trim() and replace() in order to mitigate this.
Issue resolved!

Error accessing Names in Excel using Interop

I am programming an application in C# (Visual Studio 2015) and I need to update an .xlsm file.
This file has many formulas, over 1200 names and vba code.
I am using the Interop library and I am able to update some cells and get the relative updated formulas but i have some problem with the Names defined in the Excel.
The program recognizes the names in the Names collection but doesnt let me access some of the names.
When I try to access the value of the cell using its name it produces an exception.
I dont understand why i can access some of the names and others no.
Besides, in the excel, I can see the Name in the combo but when I select it, the cursor doesn't position over the cell.
In my program I could avoid this problem accessing the cells using the reference instead of the Name, but the vba in the excel uses the names and if i open the file from my app it doesnt work.
I am using this code:
excelApplication = new Microsoft.Office.Interop.Excel.Application();
excelApplication.ScreenUpdating = true;
excelApplication.Visible = true;
excelApplication.DisplayAlerts = false;
excelWorkbook = excelApplication.Workbooks.Open(txtFicheroEntrada.Text);
wsDatos = excelWorkbook.Worksheets[1];
wsDatos.Select();
foreach(Microsoft.Office.Interop.Excel.Name v in excelWorkbook.Names)
{
string NombreVar = v.Name;
//here i found the name BobinadoAT correctly. It exists
if (NombreVar == "BobinadoAT" ){ Console.WriteLine(NombreVar); }
}
if (wsDatos.Range["BobinadoAT"] != null) //but here this produces an exception
{
string valorcelda = wsDatos.Range["BobinadoAT"].Value.ToString();
}
¿does anyone work with many excel Names?
¿Am I accessing the names incorrectly?

Move file & Rename File in Google Drive

I try to write script on Google Sheet to trigger below action.
Move a target file from root (my drive) to the destination folder then rename it in the destination folder.
Below items will be put on google sheet . I want to create a formula function to trigger the script action once below items are provide on google sheet.
Target file name
Name ID for rename
Below script works perfectly (for move file action); i would like alter below script to accomplish above action.
function copyFiles(source_folder, dest_folder) {
var source_folder = DriveApp.getFolderById(id);
var dest_folder = DriveApp.getFolderById(id);
var files = DriveApp.getFilesByName(id);
while (files.hasNext()) {
var file = files.next();
dest_folder.addFile(file);
source_folder.removeFile(file);
}
}
Thank you!!
If you just want to rename your file, you should have a look at File classe, on File.setName(name) method.
Otherwise, you question is a bit unclear and need some explanations/examples of what you trying to do.

Importing multiple excel sheets with multiple tabs into matlab

Hello and good day to all,
I am trying to import some excel sheets having multiple tabs into the matlab. For this I have written small loop but after many tries and adjustments still cant get all the data into matlab. In the source directory I have 15 excel sheets with 8 tabs each containing data in the 52 x 102 cells. The data is in signed form meaning containing positive and negative values. Here below is the code I was working on and I applied different changes which I found on the internet but no success.
srcdir = 'path to the folder';
srcfiles = dir(fullfile(srcdir, '*.xls'));
for i = 1:length(srcfiles)
[status,sheets] = xlsfinfo(srcfiles(i));
for s = 1:numel(sheets)
[data,titles]=xlsread(srcfiles(i).name,sheets{s});
end
end
Right now I am getting this error " Filename must be a string". I even tried to change it to the char to string but still didn't work.
Only once it worked When I instead of giving the path in the source directory i.e srcdir, gave the name of the file directly in xlsread().
Can anybody help where am I doing mistakes?. Thank you
You likely need to specify the full path to the file using fullfile. Also, in the outer for loop you'll need to use srcfiles(i).name instead of srcfiles(i)
srcdir = 'path to the folder';
srcfiles = dir(fullfile(srcdir, '*.xls'));
for k = 1:numel(srcfiles)
filename = fullfile(srcdir, srcfiles(k).name);
[status,sheets] = xlsfinfo(filename);
for s = 1:numel(sheets)
[data,titles] = xlsread(filename, sheets{s});
end
end

How to check a proper file in android phone's memory?

I need a method that downloads a picture and save it in SD card for later use. I got it finally, i just need an operation that checks if the file in already exists or not.
If not, the app will download it. If it is exitsts, my image view will use it.
So my question is just simple:
How to check a file in SD?
If i got this place for example:
String imageInSD = "/sdcard/1.png";
You can use the following code
String sdcardState = android.os.Environment.getExternalStorageState();
String fileName = "yourfilename" + ".png";
if (sdcardState.contentEquals(android.os.Environment.MEDIA_MOUNTED))
{
String destPath = android.os.Environment.getExternalStorageDirectory().toString()+ File.separator +fileName;
File output =new File(destPath);
if(output.exists())
\\it exists-use Imageview
else
\\Download the file accordingly
}
else
\\SDCARD not mounted

Resources