System IO File Paths

Hello all I have a question regarding the System IO namespace,I have successfully created a browser box using the utility editor.I can tell it to copy a file that I predefine or copy a entire folder:

string sourceDir = @"c:\current";
string backupDir = @"c:\archives\2008";


try
{

    string[] picList = Directory.GetFiles(sourceDir, "*.jpg");

    foreach (string f in picList)
    {
        string fName = f.Substring(sourceDir.Length + 1);
        File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName), true);
    }

I would like to be able to freely select a single.jpg file from a dictionary of 5 or so images and for it to recognize it as a file path to copy(basically find the full path for that file).
My main problem is every thing that I have tried has required a predefined path to a file or folder.

Any help would be appreciated.

The path class might be what you need

If the images you want paths to are in your Assets Directory, you might also use AssetDatabase to get paths

Thanks for that,I actually had a bit of luck with using “wwwurl”. It recognizes and finds the files paths but that flags up a error saying that it can not convert unity engine.www to a string.

Got it working. :slight_smile:
I am sure this may be useful for other people so I have attached my code below.

using UnityEngine;
using System.IO;
using System.Collections.Generic;
using UnityEditor;
           
            public class browser : MonoBehaviour
            {
                Rect WindowRect = new Rect (20,20,350,400);
                public string text = "hello";
                private string ListItem;

                public void OnGUI()
                {
                    WindowRect = GUI.Window(0, WindowRect, windowfunc, "Hello");
                }
                public void windowfunc(int id)
                {
                text = GUILayout.TextArea (text, GUILayout.Width (50), GUILayout.Height (30));
                   
                GUILayout.BeginHorizontal ();
                   
                if (GUILayout.Button ("Open")) {
                        string DestDir = @"C:\Users\Alasdair Ryan\Documents\test\Assets\";
                        string SourceDir = @"<U+202A>C:\Users\Alasdair Ryan\Desktop\game";
                        var local = Selection.activeObject;
                        string filename;
                        filename = EditorUtility.OpenFilePanel ("hi", DestDir, "jpg");
                        string fileName = filename;
                        string path = SourceDir;
                        string result1;
                        string result2;
           
                        result1 = Path.GetFileName(fileName);
                        result2 = DestDir+result1;
                        File.Copy(filename,result2,false);
        }
    }