My Project
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Properties | List of all members
FilePathName Class Reference

Files, Paths, Names and IO common methods. (Last update: 2019-10-19).. *** Reminder! File IO methods do not work with streamingAssetsPath on Android. More...

Public Types

enum  SaveFormat { NONE = -1 , GIF = 0 , JPG = 1 , PNG = 2 }
 
enum  AppPath { PersistentDataPath = 0 , TemporaryCachePath , StreamingAssetsPath , DataPath }
 

Public Member Functions

string GetAppPath (AppPath appPath)
 
string GetSaveDirectory (bool isTemporaryPath=false, string subFolder="", bool createDirectoryIfNotExist=false)
 
string GetFileNameWithoutExt (bool millisecond=false)
 
string GenerateFileNameWithDateTimeParameters (int YYYY, int MM, int DD, int hh=0, int mm=0, int ss=0, int fff=-1)
 
int CompareFileNameWithTime (string fileName_FPN, DateTime dateTime)
 Compare the filename (generated by FilePathName class) with the provided DateTime. Return -1, 0, 1. (-1: fileName time is earlier; 0: equals; 1 fileName time is later)
 
bool CheckFileNameWithinDateTimeInterval (string fileName_FPN, DateTime startDateTime, DateTime endDateTime)
 Check if the filename (generated by FilePathName class) within the Start and End DateTime interval.
 
string EnsureValidPath (string pathOrUrl)
 
string EnsureLocalPath (string path)
 
String EnsureValidFileName (String fileName)
 
string GetGifFileName ()
 
string GetGifFullPath (string subFolder="", bool createDirectoryIfNotExist=false)
 
string GetDownloadedGifSaveFullPath (string subFolder="", bool createDirectoryIfNotExist=false)
 
string GetJpgFileName ()
 
string GetJpgFullPath (string subFolder="", bool createDirectoryIfNotExist=false)
 
string GetPngFileName ()
 
string GetPngFullPath (string subFolder="", bool createDirectoryIfNotExist=false)
 
byte[] ReadFileToBytes (string fromFullPath)
 
void WriteBytesToFile (string toFullPath, byte[] byteArray)
 
void CopyFile (string fromFullPath, string toFullPath, bool overwrite=false)
 
void MoveFile (string fromFullPath, string toFullPath)
 
void DeleteFile (string fileFullPath)
 
void CheckToCreateDirectory (string directory)
 
bool PathIsDirectory (string path)
 Determine whether a given path is a directory.
 
void RenameFile (string originFilePath, string newFileName)
 
bool FileStreamTo (string fileFullpath, byte[] byteArray)
 
void WriteBytesToText (byte[] bytes, string toFileFullPath, string separator="", bool toChar=true)
 
string SaveImage (Texture2D texture, string subFolder, string fileName, SaveFormat imageFormat, Environment.SpecialFolder specialFolder=Environment.SpecialFolder.MyPictures, int jpgQuality=90)
 Saves texture as JPG/PNG on Windows/Mac.
 
string SaveBytes (byte[] bytes, string subFolder, string fileNameWithExtension, Environment.SpecialFolder specialFolder=Environment.SpecialFolder.MyPictures)
 Saves file byte array on Windows/Mac.
 
string SaveTextureAs (Texture2D texture2D, SaveFormat format=SaveFormat.JPG)
 
string SaveTextureAs (Texture2D texture2D, AppPath appPath, string subFolder, bool isJPG)
 
Texture2D LoadImage (string fullFilePath)
 
List< Texture2D > LoadImages (string directory, List< string > fileExtensions=null)
 Load images in the target directory, to a texture2D list.
 
List< byte[]> LoadFiles (string directory, List< string > fileExtensions=null)
 Load files in the target directory, to a byte[] list.
 
List< string > GetFilePaths (string directory, List< string > fileExtensions=null)
 Get file paths in the target directory.
 
IEnumerator LoadFileWWW (string url, Action< byte[]> onLoadCompleted=null, Action< WWW > onLoadCompletedWWW=null)
 Loads file using WWW. Return the byte array of the file in onLoadCompleted callback. ( IEnumerator: Remember to call this method in StartCoroutine )
 
Sprite Texture2DToSprite (Texture2D texture2D)
 

Properties

static FilePathName Instance [get]
 

Detailed Description

Files, Paths, Names and IO common methods. (Last update: 2019-10-19).. *** Reminder! File IO methods do not work with streamingAssetsPath on Android.

Member Enumeration Documentation

◆ AppPath

Enumerator
PersistentDataPath 

The directory path where you can store data that you want to be kept between runs.

TemporaryCachePath 

The directory path where temporary data can be stored.

StreamingAssetsPath 

The folder located at /Assets/StreamingAssets in the project. (Not work with System.IO methods when running on Android/WebGL)

DataPath 

The folder located at /Assets in the project. (Work on the Unity editor only)

Member Function Documentation

◆ CheckFileNameWithinDateTimeInterval()

bool FilePathName.CheckFileNameWithinDateTimeInterval ( string  fileName_FPN,
DateTime  startDateTime,
DateTime  endDateTime 
)
inline

Check if the filename (generated by FilePathName class) within the Start and End DateTime interval.

Parameters
fileName_FPNFileName generated by FilePathName class (e.g: Photo_2019-08-31-00-00-00-000.jpg/.png)
startDateTimeStart date time.
endDateTimeEnd date time.

◆ CompareFileNameWithTime()

int FilePathName.CompareFileNameWithTime ( string  fileName_FPN,
DateTime  dateTime 
)
inline

Compare the filename (generated by FilePathName class) with the provided DateTime. Return -1, 0, 1. (-1: fileName time is earlier; 0: equals; 1 fileName time is later)

Parameters
fileName_FPNFileName generated by FilePathName class (e.g: Photo_2019-08-31-00-00-00-000.jpg/.png)
dateTimeThe DateTime to be compared with the time formated file name string.

◆ GetFilePaths()

List< string > FilePathName.GetFilePaths ( string  directory,
List< string >  fileExtensions = null 
)
inline

Get file paths in the target directory.

Returns
File paths list.
Parameters
directoryDirectory.
fileExtensionsA list of file extension names, indicating the type of file paths to get. Get all file paths if Null or Empty.

◆ LoadFiles()

List< byte[]> FilePathName.LoadFiles ( string  directory,
List< string >  fileExtensions = null 
)
inline

Load files in the target directory, to a byte[] list.

Returns
Files in byte[].
Parameters
directoryDirectory.
fileExtensionsA list of file extension names, indicating the type of files to be loaded. Load all files if Null or Empty.

◆ LoadFileWWW()

IEnumerator FilePathName.LoadFileWWW ( string  url,
Action< byte[]>  onLoadCompleted = null,
Action< WWW >  onLoadCompletedWWW = null 
)
inline

Loads file using WWW. Return the byte array of the file in onLoadCompleted callback. ( IEnumerator: Remember to call this method in StartCoroutine )

Returns
The file byte array.
Parameters
urlLocal file path or http/https link.
onLoadCompletedOn load completed callback. Return the byte array of the downloaded file.
onLoadCompletedWWWOn load completed callback. Return the WWW object.

◆ LoadImages()

List< Texture2D > FilePathName.LoadImages ( string  directory,
List< string >  fileExtensions = null 
)
inline

Load images in the target directory, to a texture2D list.

Returns
The images.
Parameters
directoryDirectory.
fileExtensionsA list of file extension names, indicating the type of files to be loaded. Load jpg, png and gif if Null or Empty.

The documentation for this class was generated from the following file: