• 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 mStep · Dec 19, 2014 at 10:02 PM · editortextassetdatabase

How to keep file extension (.txt) when renaming using AssetDatabase?

I'm trying to make an editor script to create text files. At the moment I just copy a template .txt file and rename it. The problem is that I WANT the .txt extension to remain after I've created the copy, but it doesn't. In the project folder it just appears as "filename" with no extension, even when I explicitly rename the file with ".txt" appended. It just ignores it completely.

The only reason it bothers me is that I want to be able to double-click the asset in the project folder and have it automatically open in monodevelop, but that only happens if it has the .txt extension. If it doesn't, it opens in TextEdit (I'm on a Mac). If I rename the asset in the project window manually, it sticks, but that's a pain.

Here's my basic code when creating a new asset:

 TextAsset newText = (TextAsset) Resources.Load ("Text/_BLANKFILE", typeof (TextAsset));
 string newFilePath = _createAssetRootPath + fileName ;
 AssetDatabase.CopyAsset (AssetDatabase.GetAssetPath (newText), newFilePath);
 AssetDatabase.Refresh (ImportAssetOptions.Default);


Again, even including an explicit ".txt" in the path name variables doesn't do it. Anyone know how to solve this? Or am I just missing something?

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

26 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 avatar image avatar image avatar image

Related Questions

Getting assets / sub folders inside a folder 1 Answer

LoadAssetAtPath vs LoadAllAssetAtPath vs LoadMainAssetAtPath 1 Answer

Metadata not being saved on custom file types 0 Answers

!GetApplication().MayUpdate() 0 Answers

How to move an asset to a newly created directory in the AssetDatabase ? 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges