- Home /
Automatic CSV to TXT conversion [solved]
This was just asked on the beta mailing list so I thought I'd paste the question and answer here:
How can I automatically convert a CSV file to a .TXT extension so that Unity will treat it like a text asset?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Rod-Green · Dec 09, 2011 at 11:02 PM
 using UnityEngine;
 using UnityEditor;
 using System.IO;
 public class ANYoTXT : AssetPostprocessor
 {
     
     static string[] s_extensions = new string[] {"csv"};
 
     
     private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromPath)
     {
         foreach(string asset in importedAssets)
         {
             
             string lowered = asset.ToLower();
             bool doConvert = false;
             string foundExt = "";
             foreach(string eachExt in s_extensions)
             {
                 if(lowered.EndsWith("."+eachExt))
                 {
                     foundExt = eachExt;
                     doConvert = true;
                     break;
                 }
             }
             
             if(doConvert)
             {
                 if(!File.Exists(asset))
                     continue;
                 Debug.Log("Converting " + foundExt + " to TXT: " + asset.ToLower());
                 
                 string destFile = Path.GetDirectoryName(asset) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(asset) + ".txt";
                 //Debug.Log(asset + " -> " + destFile);
                 File.Copy(asset, destFile, true);
                 AssetDatabase.ImportAsset(destFile);
             }
             
             
         }
 
     }
 }
Your answer
 
 
             Follow this Question
Related Questions
How do I find a specific file type with getfiles? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Dtd validation with TextAsset xml gives exception 0 Answers
Fill variable if MemberInfo name is same as a string 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                