> 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.ksscriptupdater.md).

# Class ksScriptUpdater

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

Utility for searching and replacing regex patterns in files.

```csharp
public class ksScriptUpdater
```

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) â† [ksScriptUpdater](/reactor/api-reference/ks.unity.editor/ks.unity.editor.ksscriptupdater.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)

## Methods

### AddReplacement(string, string) <a href="#ks_unity_editor_ksscriptupdater_addreplacement_system_string_system_string" id="ks_unity_editor_ksscriptupdater_addreplacement_system_string_system_string"></a>

Adds a mapping between a search pattern and a replacement string. Once you've added all the replacements you want, call [ReplaceAll](#KS_Unity_Editor_ksScriptUpdater_ReplaceAll_System_String_2cSystem_Boolean_2cSystem_String_5b_5d_) to replace matched patterns in all files in a directory, or call [ReplaceInFile](#KS_Unity_Editor_ksScriptUpdater_ReplaceInFile_System_String_) to replace matched patterns in a single file.

```csharp
public void AddReplacement(string pattern, string replacement)
```

#### Parameters

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

Regex pattern to search for and replace.

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

Replacement string

### ExcludePath(string) <a href="#ks_unity_editor_ksscriptupdater_excludepath_system_string" id="ks_unity_editor_ksscriptupdater_excludepath_system_string"></a>

When calling [ReplaceAll](#KS_Unity_Editor_ksScriptUpdater_ReplaceAll_System_String_2cSystem_Boolean_2cSystem_String_5b_5d_), will ignore all files that begin with `path`.

```csharp
public void ExcludePath(string path)
```

#### Parameters

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

Ignore files that begin with this path.

### ReplaceAll(string, bool, params string\[]) <a href="#ks_unity_editor_ksscriptupdater_replaceall_system_string_system_boolean_system_string" id="ks_unity_editor_ksscriptupdater_replaceall_system_string_system_boolean_system_string"></a>

Replaces all patterns matches with replacements strings that were passed to [AddReplacement](#KS_Unity_Editor_ksScriptUpdater_AddReplacement_System_String_2cSystem_String_) in all files in the `directory` that match a file pattern in `filePatterns`, or all .cs scripts by default.

```csharp
public List<string> ReplaceAll(string directory = "Assets", bool recurse = true, params string[] filePatterns)
```

#### Parameters

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

Directory to process files in.

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

Should we recursively process files in subdirectories?

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

Files that match any of these patterns will be processed. If left empty, processes all cs files. Example: "\*.txt" matches all txt files.

#### Returns

[List](https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)<[string](https://learn.microsoft.com/dotnet/api/system.string)>

List of paths to files that were changed.

### ReplaceInFile(string) <a href="#ks_unity_editor_ksscriptupdater_replaceinfile_system_string" id="ks_unity_editor_ksscriptupdater_replaceinfile_system_string"></a>

Replaces all matched string patterns in a file with replacements strings.

```csharp
public bool ReplaceInFile(string path)
```

#### Parameters

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

Path to file

#### Returns

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

True if the file was changed.
