Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Dec 20, 2016 at 09:58 AM by CookieSteve for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by CookieSteve · Nov 19, 2016 at 11:15 AM · parentdirectoryfilepathfilebrowser

Using Directory.GetParent to change drives?

My project has an implemented file browser that looks like this:

alt text

In order to go up a level in the file hierarchy, the 'Up' button calls a method that returns the parent of the current directory.

 public void upDirectory(){
     dir = Directory.GetParent(dir).FullName;
     showFiles ();
 }

The problem is that I want the file browser to be able to navigate through other drives on the computer (E:\, H:\, etc), but the Directory.GetParent method only navigates as high as the root of the C drive. Attempting to go further than this throws 'NullReferenceException: Object reference not set to an instance of an object'.

Is there any way to navigate to the level of files that contains the paths to all the drives on the computer? If not, how else could I change the currently browsed drive?

filebrowser.png (15.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Nov 19, 2016 at 02:09 PM

There is nothing like a "path" or "folder" that contains drives as drives are the highest point of a path / folder on windows systems. You have to use System.IO.DriveInfo.GetDrives() which gives you a list of DriveInfo instances which represent all drives available.

Keep in mind that you might want to filter the array based on the drive type and the drive state. Drives can be empty / not ready (in case of removable drives like floppy or CD drives) and they could be readonly (like CD drives). Just check what the DriveInfo class provides.

Keep in mind that other operating systems might not have the concept of "drive letters". However if you only develop for windows that's not a problem.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Upload files to a remote webserver using unity webgl 0 Answers

EditorUtility.OpenFilePanel uses \ FileInfo.Name uses / 0 Answers

Can't Create Directory 1 Answer

Is there a way to load different drives on a Mac? 0 Answers

Directory.CreateDirectory not working 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges