View Full Version : [MEL] Open an explorer window of an other drive
Froyok 02-01-2013, 02:22 AM Hello,
I wanted to add a little feature to one of my script which would have be to open a folder from a given path by the user. Unfortunately I have something like a bug/restriction with the "system" command of Maya. I'm using Windows 7 x64 and Maya 2013.
While this work without any problem (it opens the C:\ drive with a new explorer window) :
system("explorer c: ");
The following one doesn't work and open the "user" folder ("My documents" folder) :
system("explorer d: ");
Maya is installed on my C:\ drive, so I suspect a sort of restriction... Is there a possible workaround ? Both commands work fine under a command line window, it looks like with the "system" command it's not the case.
|
|
Where Maya is installed doesn't matter, there are no restrictions other than those set by your user or group policy.
When you say running 'system("explorer D:")' doesn't work, what exactly do you mean?
Try running 'exec("explorer D:")' and see if you get a result other than 0 (0 meaning success).
Froyok
02-01-2013, 12:33 PM
Thanks for your response ! :)
What I'm saying is that Maya open a folder, but the one I want.
Every folder I try to open which are located on my C: drive is a success. However, when I try to open a folder located on my second drive, named "D:", I get the "My Documents". It's always the same.
I tried :
exec("explorer D:")
It works (I get 0), because the explorer is launched without any problem, but not where I want (it's not the folder I asked).
This morning, after the reboot of my computer it seems that
system("explorer D:")
works and open my drive D: folder (which was not the case yesterday), however, if I try to open any folder located on this drive I get the same problem as before : it opens my "My Documents" folder.
[EDIT] Haaa, I think I found why it's not working : I was not using the double "\\" (double backward slash).
Since I was calling a system command I didn't thought that the path have to be like that.
Could you please post the exact code you use in each example and cleary explain the result?
e.g.:
system("explorer D:");
// Result: Opened "C:\Users\User\My Documents"
or
system("explorer D:/myFolder");
// Result: Opened "D:\"
Froyok
02-01-2013, 12:43 PM
As I just edited in my post above : I wasn't using the double backward slash (-> \\ ) and that was the problem.
I don't know why I didn't think about sooner... :p
I thought so:
in Maya, always use forward slashes (/) to delimit folders in pathnames.
Make use of the following commands when dealing with system paths if you need a specific format:
toNativePath(string)
// Convert from '/' to '\\' path formats on Windows, otherwise does nothing. Use this proceedure to convert pathnames retrieved from Maya to more Windows-like backslash-separated pathnames (note that most Windows system calls do handle forward slashes as path-delimiters).
fromNativePath(string)
Convert from '/' to '\' path formats on Windows, otherwise does nothing. This procedure can be used to try to unify path data to use the forward slash character (a safer and more cross-platform way of handling paths, since the forward slash is what Maya uses internally to separate path names).
Froyok
02-01-2013, 01:09 PM
in Maya, always use forward slashes (/) to delimit folders in pathnames.
My path was already using it, since it was a path that I get from a fileDialog2 command.
toNativePath(string)
// Convert from '/' to '\\' path formats on Windows, otherwise does nothing. Use this proceedure to convert pathnames retrieved from Maya to more Windows-like backslash-separated pathnames (note that most Windows system calls do handle forward slashes as path-delimiters).
Thanks ! It's exactly what I was looking for ! :)
Thanks for your help !
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.