Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by thornekey · Feb 28, 2015 at 07:49 AM · c#system.iowrite datatext file

Write to text file in folder of executable

im trying to use system.io to write to a text file. That is working.. but i want to make it write to the file in the folder of the executable.. so instead of having to put a full file path it will just check the root folder dynamically.

     if (System.IO.File.Exists(@"\text.txt")) { 
         System.IO.File.AppendAllText(@"\text.txt", "my string..."); 
     }

this doesnt work.. obvisouly. How can I make it work?

Comment
Add comment · Show 2
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 hexagonius · Feb 28, 2015 at 08:51 AM 0
Share

Have you looked at this?

avatar image thornekey · Feb 28, 2015 at 10:08 AM 0
Share

that directs into the _Data folder not the folder of the exe and its dependencies.. the _Data folder throws sharing errors..

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by MinecraftProgramming · Oct 10, 2016 at 01:01 PM

@thornekey My answer is probably way to late, but I wanted to do the same thing and ended up doing it so:

 string file=Application.dataPath;
 string[] pathArray = file.Split('/');
 file="";
 for(int i =0;i<pathArray.Length-1;i++){
     file+=pathArray[i]+"/";
 }
 file+="data.json";

It's probably not the best way, but it works.

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
1

Answer by Kiwasi · Feb 28, 2015 at 10:07 AM

Typically this is bad practice. Most operating systems want you to write in the documents folder (or equivalent). This can be accessed with Application.persistiantDataPath.

However if you know what you are doing then check Application.dataPath will work.

Comment
Add comment · Show 3 · 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 thornekey · Feb 28, 2015 at 10:16 AM 0
Share

@Bored$$anonymous$$ormon the issue with persistantDataPath is that its hidden away in AppData, I was the general use to be able to access it in the same folder as the application - whereever it may be. and dataPath wont work as its protected in the _data folder..

avatar image Kiwasi · Feb 28, 2015 at 10:35 AM 0
Share

Fair enough. Can you simply parse the path to remove the _data folder? $$anonymous$$y understanding of .exe builds was they had to be in the same folder as the _data directory.

avatar image thornekey · Feb 28, 2015 at 10:52 AM 0
Share

ok Ive split the string and it i get a weird error by the document when i open it.. it says "The process cannot access the file because it is being used by another process" is there a way to close my game from using it?

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

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Move files from folder a to folder b 1 Answer

Making a bubble level (not a game but work tool) 1 Answer

Saving File from "RAM" string array only saving one file 0 Answers


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