- Home /
Convert DirectoryInfo.GetFiles data to string?
I've got an array filled using the DirectoryInfo class, however every time i try and use the data in that array, i get the error "expected "" found "/r"". Now normally ive seen this pop up for minor typos in strings but since the data im using is registering as an object i figured that could cause it too. so my dilemma is that i can't figure out how to convert the data to a string as the ToString() function doesn't seem to help. here's the relevant code so far:
 fileinfo = DirectoryInfo(Application.dataPath).GetFiles("*.ogg");
  
 for (i=0 ; i< fileinfo.Length ; i++){
 var tempstring = fileinfo[i].Replace("\", "/");
what the code is intending to do is convert the data in the fileinfo array, to a useable string for the WWW Class. however every time this is run, the "replace" line errors out with the error posted earlier. Ive hit a brick wall with this one. nothing i've found seems to help so any thoughts would be appreciated!
note that the file info variable is working as intended. i printed out the 0 variable and it was exactly what i expected. the problems i am having are to do with modifying the data contained in that variable.
Answer by POiD · Mar 02, 2015 at 02:56 PM
I believe the issue is in your use of "\". The \ character is used for escaping characters, thus you should use "\\" to actually mean . Better yet I'd use the character version of .Replace() as I have below.
I'm getting and modifying my files as follows:
 currentDirectory = new DirectoryInfo (Application.dataPath);
 foreach (FileInfo curFile in currentDirectory.GetFiles("*.ogg"))
 {
     string fileName = curFile.FullName;
 fileName = fileName.Replace('\\','/');
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                