> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/reactor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinematicsoup.gitbook.io/reactor/api-reference/ks.unity.editor/ks.unity.editor.kspathutils.md).

# Class ksPathUtils

Namespace: [KS.Unity.Editor](/reactor/api-reference/ks.unity.editor.md)\
Assembly: KSUnity-Editor.dll

Path utility functions

```csharp
[InitializeOnLoad]
public class ksPathUtils
```

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) ← [ksPathUtils](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kspathutils.md)

#### Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object\)), [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object-system-object\)), [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode), [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype), [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone), [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals), [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Properties

### ProjectRoot <a href="#ks_unity_editor_kspathutils_projectroot" id="ks_unity_editor_kspathutils_projectroot"></a>

The root of the Unity project.

```csharp
public static string ProjectRoot { get; }
```

#### Property Value

[string](https://learn.microsoft.com/dotnet/api/system.string)

## Methods

### Clean(string, bool) <a href="#ks_unity_editor_kspathutils_clean_system_string_system_boolean" id="ks_unity_editor_kspathutils_clean_system_string_system_boolean"></a>

Standardizes path seperators and optionally removes trailing slashes from a path.

```csharp
public static string Clean(string path, bool removeTrailingSlash = true)
```

#### Parameters

`path` [string](https://learn.microsoft.com/dotnet/api/system.string)

path to clean.

`removeTrailingSlash` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

If true and the path has a trailing slash, removes the trailing slash.

#### Returns

[string](https://learn.microsoft.com/dotnet/api/system.string)

### CopyFiles(string, string, string\[], string\[], LoggingFlags) <a href="#ks_unity_editor_kspathutils_copyfiles_system_string_system_string_system_string___system_string___ks" id="ks_unity_editor_kspathutils_copyfiles_system_string_system_string_system_string___system_string___ks"></a>

```csharp
public static bool CopyFiles(string fromDir, string toDir, string[] extensions = null, string[] ignoreFiles = null, ksPathUtils.LoggingFlags logging = LoggingFlags.EXCEPTIONS)
```

#### Parameters

`fromDir` [string](https://learn.microsoft.com/dotnet/api/system.string)

`toDir` [string](https://learn.microsoft.com/dotnet/api/system.string)

`extensions` [string](https://learn.microsoft.com/dotnet/api/system.string)\[]

`ignoreFiles` [string](https://learn.microsoft.com/dotnet/api/system.string)\[]

`logging` [ksPathUtils](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kspathutils.md).[LoggingFlags](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kspathutils/ks.unity.editor.kspathutils.loggingflags.md)

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### Create(string, bool, LoggingFlags) <a href="#ks_unity_editor_kspathutils_create_system_string_system_boolean_ks_unity_editor_kspathutils_loggingf" id="ks_unity_editor_kspathutils_create_system_string_system_boolean_ks_unity_editor_kspathutils_loggingf"></a>

Creates a folder path if it does not already exist.

```csharp
public static bool Create(string path, bool isFolder = false, ksPathUtils.LoggingFlags logging = LoggingFlags.EXCEPTIONS)
```

#### Parameters

`path` [string](https://learn.microsoft.com/dotnet/api/system.string)

Path to create.

`isFolder` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

true if the path is to a folder. If false, the last part of the path will not be created.

`logging` [ksPathUtils](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kspathutils.md).[LoggingFlags](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kspathutils/ks.unity.editor.kspathutils.loggingflags.md)

controls which types of messages to log.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

false if the folder does not exist and could not be created.

### Delete(string, bool, LoggingFlags, bool) <a href="#ks_unity_editor_kspathutils_delete_system_string_system_boolean_ks_unity_editor_kspathutils_loggingf" id="ks_unity_editor_kspathutils_delete_system_string_system_boolean_ks_unity_editor_kspathutils_loggingf"></a>

Deletes a file or directory, and the associated .meta file, if it exists.

```csharp
public static bool Delete(string path, bool deleteNonEmptyDirectory = false, ksPathUtils.LoggingFlags logging = LoggingFlags.EXCEPTIONS, bool deleteMetaFile = true)
```

#### Parameters

`path` [string](https://learn.microsoft.com/dotnet/api/system.string)

path to delete.

`deleteNonEmptyDirectory` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

If the path is to a non-empty directory, should we delete it?

`logging` [ksPathUtils](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kspathutils.md).[LoggingFlags](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kspathutils/ks.unity.editor.kspathutils.loggingflags.md)

controls which types of messages to log.

`deleteMetaFile` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

if true, will delete the associated meta file if it exists.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

true if the path did not exist or was deleted.

### GetDirectory(string) <a href="#ks_unity_editor_kspathutils_getdirectory_system_string" id="ks_unity_editor_kspathutils_getdirectory_system_string"></a>

Gets the directory portion of a path. If the path ends with a trailing '/' or '', it is removed before getting the directory path, so `a/b/` will return `a` instead of `a/b`. The trailing '/' or '' is not included in the returned path. Returns empty string if there is no directory portion of the path.

```csharp
public static string GetDirectory(string path)
```

#### Parameters

`path` [string](https://learn.microsoft.com/dotnet/api/system.string)

path to get directory for.

#### Returns

[string](https://learn.microsoft.com/dotnet/api/system.string)

directory

### GetName(string, bool) <a href="#ks_unity_editor_kspathutils_getname_system_string_system_boolean" id="ks_unity_editor_kspathutils_getname_system_string_system_boolean"></a>

Gets the file name portion of a path.

```csharp
public static string GetName(string path, bool includeExt = true)
```

#### Parameters

`path` [string](https://learn.microsoft.com/dotnet/api/system.string)

path to get file name for.

`includeExt` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

if false, will remove the file extension from the name.

#### Returns

[string](https://learn.microsoft.com/dotnet/api/system.string)

file name.

### IsEmptyDirectory(string) <a href="#ks_unity_editor_kspathutils_isemptydirectory_system_string" id="ks_unity_editor_kspathutils_isemptydirectory_system_string"></a>

Checks if a path is an empty directory.

```csharp
public static bool IsEmptyDirectory(string path)
```

#### Parameters

`path` [string](https://learn.microsoft.com/dotnet/api/system.string)

path to check.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

true if the path is an empty directory.

### MakeRelative(string, string) <a href="#ks_unity_editor_kspathutils_makerelative_system_string_system_string" id="ks_unity_editor_kspathutils_makerelative_system_string_system_string"></a>

Converts a path to be relative to another path.

```csharp
public static string MakeRelative(string path, string relativeTo)
```

#### Parameters

`path` [string](https://learn.microsoft.com/dotnet/api/system.string)

path to make relative.

`relativeTo` [string](https://learn.microsoft.com/dotnet/api/system.string)

path it should be relative to.

#### Returns

[string](https://learn.microsoft.com/dotnet/api/system.string)

relative path.

### Move(string, string, bool, LoggingFlags, bool) <a href="#ks_unity_editor_kspathutils_move_system_string_system_string_system_boolean_ks_unity_editor_kspathut" id="ks_unity_editor_kspathutils_move_system_string_system_string_system_boolean_ks_unity_editor_kspathut"></a>

Moves a file or directory, optionally overwriting the existing file or directory. If the source and dest are both directories, merges the source directory into the dest directory. Also moves associated .meta files, if they exist.

```csharp
public static bool Move(string source, string dest, bool overwrite = false, ksPathUtils.LoggingFlags logging = LoggingFlags.EXCEPTIONS, bool moveMetaFile = true)
```

#### Parameters

`source` [string](https://learn.microsoft.com/dotnet/api/system.string)

source file or directory to move.

`dest` [string](https://learn.microsoft.com/dotnet/api/system.string)

dest to move file or directory to.

`overwrite` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

if a dest file already exists, should we overwrite it?

`logging` [ksPathUtils](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kspathutils.md).[LoggingFlags](/reactor/api-reference/ks.unity.editor/ks.unity.editor.kspathutils/ks.unity.editor.kspathutils.loggingflags.md)

controls which types of messages to log.

`moveMetaFile` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

if true, will move the associated meta file if it exists.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

true if the file or directory was moved. When merging directories, if any files are not moved, returns false.

### ToAbsolutePath(string) <a href="#ks_unity_editor_kspathutils_toabsolutepath_system_string" id="ks_unity_editor_kspathutils_toabsolutepath_system_string"></a>

Converts a path relative to the project to an absolute path. If the path is already an absolute path, returns the path unmodified.

```csharp
public static string ToAbsolutePath(string path)
```

#### Parameters

`path` [string](https://learn.microsoft.com/dotnet/api/system.string)

path to convert to absolute path.

#### Returns

[string](https://learn.microsoft.com/dotnet/api/system.string)

absolute path.

### ToAssetPath(string) <a href="#ks_unity_editor_kspathutils_toassetpath_system_string" id="ks_unity_editor_kspathutils_toassetpath_system_string"></a>

Converts a full path to a Unity asset path.

```csharp
public static string ToAssetPath(string path)
```

#### Parameters

`path` [string](https://learn.microsoft.com/dotnet/api/system.string)

path to convert.

#### Returns

[string](https://learn.microsoft.com/dotnet/api/system.string)

Unity asset path.

### Unzip(string, string) <a href="#ks_unity_editor_kspathutils_unzip_system_string_system_string" id="ks_unity_editor_kspathutils_unzip_system_string_system_string"></a>

Unzip a file to a destination directory.

```csharp
public static void Unzip(string filePath, string destDir)
```

#### Parameters

`filePath` [string](https://learn.microsoft.com/dotnet/api/system.string)

Path to a zip file.

`destDir` [string](https://learn.microsoft.com/dotnet/api/system.string)

Destination directory
