概要
以下のようなjpgフォルダの中に様々な画像があります。
その中で、最も古いファイルだけを削除するにはどうすればいいでしょうか。
![](http://aftp.tokyo/wp-content/uploads/2020/01/image-86.png)
工程
- 指定したフォルダ内のファイル一覧(作成日時を含む)をデータテーブルとして取得
- 取得したデータテーブルを作成日順に昇順
- 最も古いファイルパスを削除
ワークフロー
概要
用意したワークフローは以下のとおりです。
![](http://aftp.tokyo/wp-content/uploads/2020/01/image-45.png)
データテーブルを構築
データテーブル変数「folder_DT」を以下のように構築します。
![](http://aftp.tokyo/wp-content/uploads/2020/01/image-46.png)
フォルダ内のファイルパスを繰り返し処理
System.IO.Directory.GetFilesメソッドで指定したフォルダ内のファイルパスを繰り返し取得
![](http://aftp.tokyo/wp-content/uploads/2020/01/image-47.png)
新規行にファイルパスと、作成日時を追加します。
プロパティ画面は以下の通りです。
![](http://aftp.tokyo/wp-content/uploads/2020/01/image-37.png)
以下のようにファイルパスと 作成日時のデータテーブルが生成されました。
![](http://aftp.tokyo/wp-content/uploads/2020/01/image-36.png)
データテーブルを作成日時順に並び替え
System.IO.Directory.GetFiles(“フォルダパス”)で取得されるディレクトリの順番はバラバラです。
ファイルシステムは2パターンあって、NTFSかFAT32のいずれかです。で、ファイルシステムがどちらかによって取得される順番は異なってきます。詳細は省略しますが、いずれにしても作成日時順に自動的になるわけではないです。
よって、 データを並び替えます。
![](http://aftp.tokyo/wp-content/uploads/2020/01/image-49.png)
最も古いファイルパスを削除
folder_DTの先頭行が最も古いファイルになったので、それを削除します。
※ゴミ箱からも削除されます。
![](http://aftp.tokyo/wp-content/uploads/2020/01/image-50.png)
無事に削除されました。
![](http://aftp.tokyo/wp-content/uploads/2020/01/image-51.png)
GitHubはこちら
感想
ほとんどUiPath独自のメソッドは使っておりません。すべてVB.NETなどでよく利用されているものばかりです。今度はVBAでも同じことをやってみようと思います。
28件のフィードバック
buying prescription drugs in mexico online: mexican pharmacy online – mexican rx online
You actually make it seem so easy along with your presentation but I to find this
topic to be really one thing which I feel I would never understand.
It seems too complex and very huge for me.
I am taking a look ahead for your subsequent submit, I will try to get the cling of it!
Escape room
Very interesting information!Perfect just what I was searching
for!?
buying prescription drugs in mexico: mexican pharmacy – mexico drug stores pharmacies
mexico pharmacies prescription drugs: buying from online mexican pharmacy – mexico pharmacy
canadian pharmacy scam: pet meds without vet prescription canada – safe canadian pharmacy
top online pharmacy india: indian pharmacy paypal – top online pharmacy india
legitimate canadian online pharmacies: canadian pharmacy meds – canadian pharmacy no scripts
canadian mail order pharmacy: best canadian pharmacy – legit canadian pharmacy
mexican online pharmacies prescription drugs: buying from online mexican pharmacy – buying prescription drugs in mexico
mexican pharmaceuticals online: mexico pharmacy – purple pharmacy mexico price list
my canadian pharmacy review: canadian medications – canadian online drugstore
mexican mail order pharmacies: mexican mail order pharmacies – mexican drugstore online
https://ciprodelivery.pro/# ciprofloxacin generic price
http://clomiddelivery.pro/# buying generic clomid
paxlovid for sale [url=https://paxloviddelivery.pro/#]paxlovid cost without insurance[/url] paxlovid pharmacy
https://paxloviddelivery.pro/# paxlovid pill
https://amoxildelivery.pro/# antibiotic amoxicillin
paxlovid for sale [url=https://paxloviddelivery.pro/#]paxlovid price[/url] paxlovid pharmacy
http://amoxildelivery.pro/# amoxicillin brand name
https://ciprodelivery.pro/# buy cipro
generic doxycycline online [url=http://doxycyclinedelivery.pro/#]doxycycline usa[/url] doxycycline tablets in india
http://doxycyclinedelivery.pro/# doxycycline 40 mg india
http://doxycyclinedelivery.pro/# can i buy doxycycline over the counter
ciprofloxacin [url=https://ciprodelivery.pro/#]ciprofloxacin mail online[/url] where can i buy cipro online
https://paxloviddelivery.pro/# paxlovid pill
https://ciprodelivery.pro/# ciprofloxacin mail online
generic clomid without a prescription [url=http://clomiddelivery.pro/#]can i get clomid without prescription[/url] where can i buy clomid without insurance
https://amoxildelivery.pro/# amoxicillin online pharmacy
http://ciprodelivery.pro/# ciprofloxacin order online
https://amoxildelivery.pro/# order amoxicillin uk
amoxicillin 500 mg tablet [url=https://amoxildelivery.pro/#]amoxicillin 500 mg cost[/url] buy amoxicillin 500mg capsules uk
https://doxycyclinedelivery.pro/# doxycycline price usa
https://doxycyclinedelivery.pro/# doxycycline 20 mg capsules
doxycycline nz cost [url=https://doxycyclinedelivery.pro/#]doxycycline hyclate 100 mg cap[/url] doxycycline with out a rx