Move file to different folders Depending on the file names

Hi team,

I have 4 files
(PNA KLM Add data_MM_dd_yyyy
PNA KLM Product_MM_dd_yyyy
PCA KLM Add data_MM_dd_yyyy
PCA KLM Product_MM_dd_yyyy
) under Data\temp folder (Source folder) under my project. I want to move them to different folders depending on their names.

  • send to Product folder product related files (PCA KLM Product_MM_dd_yyyy, PNA KLM Product_MM_dd_yyyy),

  • send to Add Data folder Add data related files (PNA KLM Add data_MM_dd_yyyy, PCA KLM Add data_MM_dd_yyyy)

Can anyone help with this?

Thanks!

For Each File in Folder for Data\temp

  • If CurrentFile.Name.Contains(“Product”) Then Move File to Product folder
  • Else Move File to Add Data folder

Hi,

There are some ways to achieve it. The following is one of them using switch.

Sample20230602-1L.zip (3.9 KB)

Regards,

Hi @Yoichi

The process ran without error but did not move the files.
I’ve a follow up question
How does this expression identify the two different folder paths?
System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileNameWithoutExtension(currentItem).ToLower,“product|add data”).Value

Also, the destination folders are outside of the project scope.
something like

Desktop\RPA_Folder\Add Data
Desktop\RPA_Folder\Product

If input is “PNA KLM Add data_MM_dd_yyyy”, the above expression returns “add data”
if input is “PNA KLM Product_MM_dd_yyyy”, the above expression returns “product”
then switch by the result.

I just added some write line activity. Can you try the following and share its logs in Output panel?

Sample20230602-1L (2).zip (4.0 KB)

Regards,

Hi @Yoichi

Here is the screenshot.

HI,

The expression seems lack of ToLower method. Please add .ToLower as the following

System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileNameWithoutExtension(currentItem).ToLower,"product|add info").Value

Regards,

@Yoichi

Thanks a lot! That has worked

1 Like

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