- Home /
Accessing the computer's local files
Hey guys,
Sorry about this primitive question, but I can't figure out how to access the computer's local files. I want to-as an example-go into the users photo collection, and gather all the pictures, then display them in a photo album inside Unity. Also, I want to save and delete files from that directory (with the users permission, of course-I'm not trying to make a virus)
I have tried searching for about five minutes and I didn't find anything, so I thought I would ask. Please let me know if this is possible, and if it is, how to do it. Also, an example would be great!
Thanks for your time - Gibson
Answer by DaveA · Jul 12, 2011 at 04:37 AM
You could try the file:// prefix with the WWW class, but better to check the msdn: http://msdn.microsoft.com/en-us/library/system.io.file.aspx
Well, I am a bit of a novice... Is there a way to do any of those things Unity's Java Script? It says that Java script is not supported. Also, will this work on $$anonymous$$acs?
Also. is it possible to turn the following into a Java Script code?
public static void $$anonymous$$ove(
string sourceFileName,
string destFileName
)
Yes, UnityScript uses a port of the .net framework. you can, and should, use all the wonderful methods you can find on msdn.microsoft.com
In this case, System.IO.File is exactly what you want.
Well first of all, you're using an other namespace. So at the top of your script you write:
import System.IO;
then the $$anonymous$$ove function in javascript would be: static function $$anonymous$$ove( sourceFileName : String, destFileName : String );
Read up on the examples, try to learn very basic C# so you can translate it into JS, and you're golden. The examples are very good on $$anonymous$$SDN. The one for this method shows you need to give it two paths, for intance @"c:\temp\$$anonymous$$yTest.txt" and it will move the File from the first path to the second.
Once you import System.IO; you can use all methods within it directly. So yes, you can write:
var pathOne : String = "...";
var pathTwo : String = ".......";
File.$$anonymous$$ove( pathOne, pathTwo );
and you're done. This is why the dot net framework is so extremely nice. It allows you to do nearly anything.
But remember that accessing the file system is not supported if you are building a web player.
Your answer
Follow this Question
Related Questions
deleting the content of a directory using javascript. 0 Answers
Change Playerpref location directory 0 Answers
Asset Bundles - loading locally and few questions 0 Answers
Unity Serializer - saves delete after restarting game 2 Answers
Download and save images into local phone storage makes the app hang 1 Answer