フォルダ内に指定ファイルがあるか確認

指定フォルダ内に[aaa.CSV,bbb.CSV,ccc.CSV]のファイルが存在すれば後続処理実行。
というならシナリオを作成したいです。

files[Strig]={aaa.CSV,bbb.CSV,ccc.CSV}
checkFiles[Strig]=Directory.GetFiles(“指定するパス”)

for each file in checkFiles??
とここまではなんとか浮かぶんですが、、、
それ以降で煮詰まってしまい。
ご教示頂きたく思いました。

1 Like

@kunie

Try this:

strFiles [ ] = Directory.GetFiles(“FolderPath”)

Then use For Each loop to itreate the files.

ForEach item in strFiles
Print item

1 Like

Thanks!
I knew it to loop, but
I’m wondering what to do with the processing in the loop

2 Likes

@kunie

What are you trying to do after getting files ?

1 Like

Merge 3 files if it is.
If there is not, I want to display a message box.

1 Like

こんな感じでどうですか?
Array.IndexOf() で、取得したファイル一覧(chkfiles) の中に、指定したファイル(c:\temp\a.csv)があるかを1個ずつ判定しています。
ファイルがあったら条件分岐がTrueになるので左側の箱に行ってファイル名が表示される、という流れです。

1 Like

上記例はファイルが存在したら都度実行なので、3個存在したら3回実施してしまいますね。
指定したファイルの「どれか一つがあったら後続処理実行」という場合は、左の箱をbooleanのフラグにしておいて、
繰返しを抜けたらもう一回条件分岐でフラグがオンなら、とかやるのですかね。

1 Like

@kunie

Do you want to check is it three files or not right ?

Then after this expression try this:

Int32 fileCount = strFiles.count

If fileCount = 3
Then merge Files
Else
print Files are less than 3

As it is CSV files, use Read CSV File Activity to read the the data and will give output as DataTable and then use Merge DataTable Activity to merge files.

1 Like

Hi @kunie

  • Get the files Using Directory.Getfiles(YourFolderpath,“*.csv”) It will get all the csv files from the folder as the array of string.
    -Then Use for each loop to iterate files.
    -Use Read Csv Activity to Read the all files one by one.
    Regards
1 Like

ご指定のファイルの配列に含まれるファイルが「すべて存在しないといけない」前提での回答です。

ファイルの配列に対してFor eachを使ってひとつずつ抽出し、
ひとつひとつのファイルを、Path Existsで確認し、結果を変数に入れます。
確認したあと、Ifアクティビティで結果の変数がfalse、つまり存在しない場合にはBreakします。

もしすべてのファイルがあれば、Path Existsはすべてのファイルでtrueになりますので、For eachを抜けたあともtrueです。
逆にひとつでもファイルが無ければ、Path Existsがそのタイミングでfalseになり、そのfalseの状態でBreakするので、For eachを抜けたあともfalseになります。

test_checkfiles.xaml (7.0 KB)

1 Like

ありがとうござます。
教えて頂いた方法で、GetFileNameを設定すれば、
ファイル名取得できました。
Array.IndexOf(checkfile,GetFileName(item).Tostring)

2 Likes

@lakshman
@jitendra_123
@cheez_RPA
Thanks!
It worked well thanks to various wisdom

2 Likes

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