Process.Start - opening explorer.exe to a parent of the Application.dataPath folder

Hi All

I have a screenshot function with two buttons - one takes a screenshot, and the other opens the folder location where the screenshots are saved.

I don’t want the screenshots saved into the data folder, but instead to a new folder that is created one level up called ‘Screenshots’.

I achieve this in the screenshot phase by creating a string variable to hold the data path as follows:

screenshotFilePath = Application.dataPath + "/../" + "/Screenshots/";

However for the open file location phase, it doesn’t seem to respect the same syntax and literally tries to insert the /…/ into the data path. Here is my code:

        string filePath = screenshotFilePath;
        string filePathFixed = filePath.Replace(@"/", @"\");
        System.Diagnostics.Process.Start("explorer.exe" , "/select," + filePathFixed);

If I print this, it gives me the following:

[datapath]..\Screenshots\

As you can see, the /…/ no longer moves up by one directory, but is inserted literally into the path. Can anyone advise what the correct syntax is for the System.Diagnostic.Process.Start to navigate folders?

Thanks

While I didn’t try it, I’m surprised that a “…/” within a path doesn’t back up a folder when used with Process.Start. Are you sure that’s true? Anyway, the following should construct a proper path without using the “…/” syntax:

// Get the parent path of the Application data path
string parentPath = Directory.GetParent(Application.dataPath);
// Add a "Screenshots" level to the path
string screenshotFilePath = Path.Combine(parentPath, "Screenshots");

Jeff

I tried to use this code today as I ran into the same issue (code from original OP was working fine for launching an .exe but not for setting a string parameter), got all sorts of errors. Here they are some, the others derive from these two:

Cannot implicitly convert type System.IO.DirectoryInfo' to string’
Argument #1' cannot convert object’ expression to type `string’

I obviously didn’t test the above snippet. Looking, I see that Directory.GetParent returns a DirectoryInfo object (not a simple string). So, with that in mind, you need to get the “path” portion from the DirectoryInfo object. So, something like this (again, untested…):

    // Get the parent path of the Application data path
    DirectoryInfo di = Directory.GetParent(Application.dataPath);
    string parentPath = di.FullName; 
    // Add a "Screenshots" level to the path
    string screenshotFilePath = Path.Combine(parentPath, "Screenshots");
1 Like

Ahh thanks for the quick answer Jeff - I was wondering how to convert that. Just got this working with your new code and moving it into the Start method. Much gratitude for the great suggestion, quick response and pleasant attitude! :slight_smile:

oops, this popped up in my feed today and I realised I hadn’t thanked Jeff for his original help - thanks a lot man!