SrejonKhan/AnotherFileBrowser

Issue with Initial Directory for Browser Properties

Opened this issue · 8 comments

Hi,

Before anything I just want to say that this package is such a huge help. Its so simple and clean, and gets the job done too.

However, its not getting the job done if I put anything for the initial director in the browser properties.

The path I want to put in is the path to a folder called images in the resources folder in my project. To do this I write this:
bp.initialDir = Application.dataPath + "/Resources/Images";

I first thought that the issue was that the path can't access the Resources folder for some weird reason so I tried just going to a folder on my desktop:
bp.initialDir = "C:\Users\Matthew\Desktop\TestFolder";

That also didn't work.

Also I have boiled this problem down to exactly the initial directory variable. With that code it breaks, without it it doesn't. And I tried commenting out other parts of my code to see if any of that was the problem and its not.

So I am assuming this is a problem with "AnotherFileBrowser" code.

Anyway, is there anything I could do or can anyone help me?

I will check and let you know. Thanks.

I will check and let you know. Thanks.

Wow thanks, that was very fast. I also checked to see if the problem was that the "restoreDirectory" had to be set to false for it to work, but the problem persisted.

It should be good now. Please check and let me know.

It should be good now. Please check and let me know.

The issue is still there, however, I see now why it exists. The problem is the path format. You seem to be using a pathing format that uses the "@" symbol and uses this slash: "\".

Unity's "Application.dataPath" does not use the "@" symbol and it uses this slash "/"

I do not know how to put the @ symbol in front of the Application.dataPath variable so I can't use your format. You might need to allow for string paths that are formatted like unity formats it or I might be missing something simple that allows for the conversion from unity to yours.

@ can be used before string literal, not a string variable. For example -

string s = Application.dataPath + @"\folder"; // this will work
string s = @Application.dataPath + "\folder"; // this will not work

@ before any variable name or Class name is basically used for to use any reserved word as variable name. For example -

string @class = "ClassName"; // this will work and no error 
@class = "AnotherClassName"; // accessing later

string class = "ClassName"; // this will not work because class is a reserved word. 

There is another alternative option available, which is considered safe for every environment. Use Path.Combine(). For example -

string path = Path.Combine(Application.dataPath, "FolderName", "NestedFolder");

Make sure to add directives using System.IO at the top of the class.

I used Path.Combine and it still didn't work. It must a hardware/software thing and not your code since it works for you and not for me. But anyways thanks for the help, I think I am just gonna give up on that. I'm still using your code though and it's a life saver so thanks!

I did a small bit more testing and I found out that the "Application.dataPath" returns a path that has backslashes while I was trying to combine it with forward slashes. Also the Path.Combine method also uses forward slashes. So when I fixed that it didn't give any errors and opened windows explorer. However, it just opened to the most recent directory instead of where I specified. I also tried it again with the restoreDirectory variable set to false.

i need help , because i can't use initialDir to choose folder desire