# Renaming and saving text files based on its content

**URL:** <https://forums.powershell.org/t/renaming-and-saving-text-files-based-on-its-content/23631>\
**Category:** PowerShell Help\
**Created:** [February 22, 2024, 7:20pm UTC](https://forums.powershell.org/t/renaming-and-saving-text-files-based-on-its-content/23631 "2024-02-22T19:20:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamCem](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@SamCem](https://forums.powershell.org/u/SamCem)\
**Post date:** [February 22, 2024, 7:20pm UTC](https://forums.powershell.org/t/renaming-and-saving-text-files-based-on-its-content/23631/1 "2024-02-22T19:20:38Z")

</div>

Hi,  
I’ve got hundreds of .html-Files of a Forum and I want to rename and save them the following way. Each File consists, among many other lines, of the following line:

```auto
<td align="left" valign="middle" class="nav" width="100%"><span class="nav"><a href="index.php?sid=a6ddafec8f3ed8a0a7cf4f8bf8273cff" class="nav">ONE</a><a href="./index.php" class="nav">TWO</a>&nbsp;&raquo;&nbsp;<a href="./viewforum.php" class="nav">THREE</a><a href="./viewtopic.php" class="nav">FOUR</a></span></td>

```

My goals: _(THREE, FOUR are just a placeholders here and different in each file)_

1. Rename each file to “FOUR.html”
2. save the file in directory: “Forum/THREE”

How is this possible in a smart way using PowerShell on Windows 10?  
Thank you very much!

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 22, 2024, 7:53pm UTC](https://forums.powershell.org/t/renaming-and-saving-text-files-based-on-its-content/23631/2 "2024-02-22T19:53:58Z")

</div>

Sam,  
Welcome to the forum. 👋🏼

This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

We actually expect you to make an own attempt at the first place to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.

To get you started you may start to read the help for the following PowerShell cmdlets:

> **[Get-ChildItem (Microsoft.PowerShell.Management) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-7.4)**
>
> The Get-ChildItem cmdlet gets the items in one or more specified locations. If the item is a container, it gets the items inside the container, known as child items. You can use the Recurse parameter to get items in all child containers and use the...

> **[ForEach-Object (Microsoft.PowerShell.Core) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-7.4)**
>
> The ForEach-Object cmdlet performs an operation on each item in a collection of input objects. The input objects can be piped to the cmdlet or specified using the InputObject parameter. Starting in Windows PowerShell 3.0, there are two different ways...

> **[Get-Content (Microsoft.PowerShell.Management) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=powershell-7.4)**
>
> The Get-Content cmdlet gets the content of the item at the location specified by the path, such as the text in a file or the content of a function. For files, the content is read one line at a time and returns a collection of objects, each...

> **[about Comparison Operators - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-7.4)**
>
> Describes the operators that compare values in PowerShell.

> **[Select-String (Microsoft.PowerShell.Utility) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string?view=powershell-7.4)**
>
> The Select-String cmdlet uses regular expression matching to search for text patterns in input strings and files. You can use Select-String similar to grep in UNIX or findstr.exe in Windows. Select-String is based on lines of text. By default,...

> **[Rename-Item (Microsoft.PowerShell.Management) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/rename-item?view=powershell-7.4)**
>
> The Rename-Item cmdlet changes the name of a specified item. This cmdlet does not affect the content of the item being renamed. You can't use Rename-Item to move an item, such as by specifying a path together with the new name. To move and rename an...

Please always read the help for the cmdlets you’re about to use completely including the examples to learn how to use them.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [March 23, 2024, 7:54pm UTC](https://forums.powershell.org/t/renaming-and-saving-text-files-based-on-its-content/23631/3 "2024-03-23T19:54:20Z")

</div>

Closed on March 23, 2024, 7:54pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
