[MEL] Open an explorer window of an other drive

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  02 February 2013
[solved] (MEL) Open an explorer window of an other drive

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.
__________________
Dev-blog : http://www.froyok.fr/blog

Last edited by Froyok : 02 February 2013 at 02:10 PM.
 
  02 February 2013
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).
 
  02 February 2013
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.
__________________
Dev-blog : http://www.froyok.fr/blog

Last edited by Froyok : 02 February 2013 at 01:41 PM.
 
  02 February 2013
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:\"
 
  02 February 2013
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...
__________________
Dev-blog : http://www.froyok.fr/blog
 
  02 February 2013
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).
 
  02 February 2013
Originally Posted by Nyro: 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.

Originally Posted by Nyro: 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 !
__________________
Dev-blog : http://www.froyok.fr/blog
 
  02 February 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 12:11 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.