# ファルダ内にあるファイルのリネームについて

**URL:** <https://forum.uipath.com/t/topic/521442>\
**Category:** Automation Ops\
**Tags:** question, system, activities\
**Created:** [February 28, 2023, 4:32am UTC](https://forum.uipath.com/t/topic/521442 "2023-02-28T04:32:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![a.kmni](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@a.kmni](https://forum.uipath.com/u/a.kmni)\
**Post date:** [February 28, 2023, 4:32am UTC](https://forum.uipath.com/t/topic/521442/1 "2023-02-28T04:32:40Z")

</div>

いつもお世話になっております。

繰り返し（フォルダー内の各ファイル）アクティビティを使用して複数あるフォルダ内の各ファイルのリネームをしたいと考えています。

①XXXXXXXX.pdf→XXXXXXXX\_合格.pdf  
→この場合は「\_合格」を追加

②XXXXXXXX.aaaa.pdf→XXXXXXXX\_合格.pdf  
→この場合は「aaaa」を削除、「\_合格」を追加

①、②のように既存のフォルダ名（XXXXXXXX）を残して、その後ろに「\_合格」を追加して保存をしたいのですが、可能でしょうか？

既存のフォイル名（フルパス）を取得することはできたのですが、一部を残しつつ変更する方法がいまいちわからなかったので質問させていただきます。

ご教示いただけますと幸いです。

---

<div class="post-metadata">

**Author:** ![Sudharsan\_Ka](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sudharsan_ka/32/459826_2.png) [@Sudharsan\_Ka](https://forum.uipath.com/u/Sudharsan_Ka)\
**Post date:** [February 28, 2023, 5:42am UTC](https://forum.uipath.com/t/topic/521442/2 "2023-02-28T05:42:32Z")

</div>

HI @a.kmni

You can use For each File in Folder

- If condition

```auto
System.Text.RegularExpressions.Regex.IsMatch(Path.GetFilenameWithoutExtension(CurrentFile.tostring),"\.\D+\.")

```

True → Rename File  
- File → CurrentFile.Tostring  
- New File Name → System.Text.RegularExpressions.Regex.Replace(Path.GetFilenameWithoutExtension(CurrentFile.tostring),“.\D+.”,“\_合格”)

False → Rename File  
- File → CurrentFile.Tostring  
- New File Name → Path.GetFilenameWithoutExtension(CurrentFile.tostring)+“\_合格”

 ![image](https://global.discourse-cdn.com/uipath/original/4X/e/4/a/e4ae69434343522922c5536dbe7ea30d37fca982.png)

Note : In Rename File activity , Enable Keep Extension in then and false

Hope this Helps!

Regards  
Sudharsan

---

<div class="post-metadata">

**Author:** ![a.kmni](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@a.kmni](https://forum.uipath.com/u/a.kmni)\
**Post date:** [March 2, 2023, 1:32am UTC](https://forum.uipath.com/t/topic/521442/3 "2023-03-02T01:32:38Z")

</div>

[Sudharsan\_Ka](https://forum.uipath.com/u/Sudharsan_Ka)  
こんにちは。

教えていただきありがとうございます！

System.Text.RegularExpressions.Regex  
→文字列の操作をする  
Path.GetFilenameWithoutExtension  
→拡張子無しのファイル名を取得する

以上のように式の認識をいたしましたが間違いないでしょうか？

質問ばかりで申し訳ないのですが、  
・Else(CurrentFile.tostring)+“\_合格”  
→①XXXXXXXX.pdf→XXXXXXXX\_合格.pdf これを実現

・条件式(CurrentFile.tostring),“.\D+.”)  
・Then(CurrentFile.tostring),“.\D+.”,“\_合格”  
こちらの2点がどうしてもわかりません・・・  
おそらく②XXXXXXXX.aaaa.pdf→XXXXXXXX\_合格.pdfを実現するものだとは思うのですが、高度な文字列操作に慣れておらず・・・

ご教示いただけますと幸いです。

---

<div class="post-metadata">

**Author:** ![a.kmni](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@a.kmni](https://forum.uipath.com/u/a.kmni)\
**Post date:** [March 2, 2023, 2:46am UTC](https://forum.uipath.com/t/topic/521442/4 "2023-03-02T02:46:18Z")

</div>

いつもお世話になっております。

(CurrentFile.tostring)以降を変えてみました。  
削除したい文字列「.aaaa」は統一でしたので、「.aaaa」が含まれているか、  
「.aaaa」が含まれている場合は、「\_合格」に置換、  
「.aaaa」が含まれていない場合は、「\_合格」を追加（こちらは教えていただいた通りです）

としましたところ、うまくできました。  
あがとうございました！

> Condition:
> 
> > System.Text.RegularExpressions.Regex.IsMatch(Path.GetFilenameWithoutExtension(CurrentFile.tostring),“.aaaa”)

> Then:
> 
> > System.Text.RegularExpressions.Regex.Replace(Path.GetFilenameWithoutExtension(CurrentFile.tostring),“.aaaa”,“\_合格”)

> Else:
> 
> > Path.GetFilenameWithoutExtension(CurrentFile.tostring)+“\_合格”

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [March 5, 2023, 2:47am UTC](https://forum.uipath.com/t/topic/521442/5 "2023-03-05T02:47:18Z")

</div>

Closed on March 5, 2023, 2:47am UTC

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