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 /
avatar image
5
Question by davedev · Feb 19, 2010 at 09:26 PM · datapath

Can I get a folder up hierarchy relative to the dataPath?

So I have something like this:

var mpDataPath = Application.dataPath;
var files = Directory.GetFiles(mpDataPath);

but I'd like to NOT have my data files in Assets at runtime (the keep getting imported into Unity authoring) and NOT in my _Data folder at runtime, but maybe up one level.

Are there any symbols I can use to indicate "up one folder level"?

Does Unity allow this if I for example just edit the dataPath string to represent the folder up one level.

My folders might be look this:

application.exe
application_Data
mpData
  data files...
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

6 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by duck · Feb 19, 2010 at 10:06 PM

Even better than a symbol, the "Directory" class has a function to do just this called "Parent". Check it out on MSDN here.

And to get a fuller understanding of the use of files and paths in unity, using .net's FileIO, check out these pages:

  • the File class (MSDN)
  • the Directory class
  • C# reading and writing files

(even if you're using javascript, the c# reference will be useful, since all the functions and variable names for the .net classes are exactly the same!)

Comment
Add comment · Show 1 · 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
avatar image Eric5h5 · Feb 19, 2010 at 10:18 PM 0
Share

Also if you're using Javascript, switch the syntax to JScript in the $$anonymous$$SDN docs, and that will almost always be identical to what you use in Unity. They typically don't have JScript example code though.

avatar image
3

Answer by Eric5h5 · Feb 19, 2010 at 10:14 PM

If you want to use symbols, ../ is the usual way.

var oneLevelUp = Application.dataPath + "/../";
var dirInfo = new System.IO.DirectoryInfo(oneLevelUp).GetFiles();
for (fileName in dirInfo) {
    print (fileName);
}
Comment
Add comment · Show 1 · 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
avatar image davedev · Feb 20, 2010 at 10:19 AM 0
Share

Huh, I had tried that initially, but maybe I messed it up in some way...

avatar image
1

Answer by JDonavan 1 · Feb 19, 2010 at 10:27 PM

This is a horrible hack but it works. At least from run mode in the IDE...

using UnityEngine; using System.Collections; using System.IO;

public class TestPath : MonoBehaviour {

 // Use this for initialization
 void Start () {
     string assetsPath = Application.dataPath;
     string configPath = assetsPath.Substring(0,assetsPath.LastIndexOf('/')) + "/config";
     string[] files;
     string input;
     StreamReader reader;

     Debug.Log(Application.dataPath);
     Debug.Log(configPath);
     files = Directory.GetFiles(configPath);

     foreach (string fileName in files)
     {
         reader = File.OpenText(fileName);
         Debug.Log(fileName);
         while ((input = reader.ReadLine()) != null)
         {
             Debug.Log(input);
         }
         reader.Close() ;

     }
 }

 // Update is called once per frame
 void Update () {

 }

}

Comment
Add comment · Show 2 · 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
avatar image davedev · Feb 20, 2010 at 10:17 AM 0
Share

The "LastIndexOf" is part is actually cool. Where does that function come from. I haven't seen many string functions in the Unity Scripting Refrence

avatar image Eric5h5 · Feb 20, 2010 at 12:56 PM 0
Share

You won't find any of the $$anonymous$$ono/.NET functions in the Unity scripting reference. Use the $$anonymous$$ono or $$anonymous$$SDN docs for that.

avatar image
1

Answer by davedev · Mar 13, 2010 at 09:00 PM

Not the exact answer, but related, I recently found the Path class in Unity which has functions for manipulating paths like GetDirectoryName, GetFileName.

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
avatar image
0

Answer by pavlito · Oct 21, 2015 at 01:58 PM

We use a centralized point for gameLogic so we put an .exe outside assets folder. The hierarchy is as follows:

(Assets): D:/Projects/ProjectName/Assets

(GameLogic): D/Projects/ProjectName/offline

(Database): D:/Projects/ProjectName/offline/db

Here is the code to fetch the desired .exe relative to assets

 void Start()
 {
       StartServerProcess();
 }
 void StartServerProcess()
 {
       var stringPath = Application.dataPath + "/../offline/";
       string directory = Path.GetFullPath(stringPath);
       var myProcess = new System.Diagnostics.Process();
       myProcess.StartInfo.WorkingDirectory = directory;
       myProcess.StartInfo.FileName = "offline.exe";
       myProcess.Start();
 }
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
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

When to use persistentDataPath versus dataPath 1 Answer

Path for Assets/Textures folder File in Android 2 Answers

Caching external text files 1 Answer

Is there a way to change the Application.dataPath? 0 Answers

where to put XML files in unity project ? 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