Move and rename files with increasing sequence number

I am saving mail attachments, reading, sorting, moving and renaming the files into categories based on its contents.

For each file that has Condition X I move and save the file as filename condition X
My problem is that my loop gets an error when it tries to save the second file with condition X in the folder. Error msg says It cant create a new file, when the file already exists. (same name). So I want each file til be named Condition X 1, Condition X 2, Condition X 3 etc.

How do i add the (+1) to the destination filename?

@NilsSvendsen
Welcome to the forum

maybe you can give some more details on how you do loop over the files.

In case of you are working with a for each activity have a look on the Index output
grafik

this will provide the information on the current interation and you can use it with e.g. “YourfileName_” + IndexVar.toString

1 Like

Hi,

How about the following?

fileName = "CondirionX"+(System.IO.Directory.GetFiles(yourPath,"ConditionX*").Count()+1).ToString()+".ext"

Regards,

1 Like

For each file i read text file
IF text contains S9
Then
IF text contains SU12
then
Move file to destination \ “S9_SU12 “+ToDaysDate+”.txt”

1 Like

@Yoichi
That is working. Thank you!

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