Search files

Hi these are some sample files in a folder and I want to search it based on the first five digits like 10001 and moved to another folder. I want to do it one by one. Plz guide how can I do this.
image

@Palaniyappan @lakshman @Lahiru.Fernando

Hi
Kindly follow the below steps that could help you resolve this buddy
-use a assign activity like this
out_filepatharray = Directory.GetFiles(“yourfolderpath”,"*.pdf")
where out_filepatharray is a variable of type string array
–use a for each loop and pass the above variable as input and change the type argument as string
–inside the for each loop use a if condition like
item.ToString.Contains(“10001”)
if this conditions gets passed itwill go to THEN part where we can use
move file activity and pass the input for source path as item (as it holds the file path)
and destination path as folder path between double quotes (as string) where you want to move

Hope this would help you
Kindly try this and let know for queries or clarification
Cheers @balkishan

3 Likes

Hi @balkishan

First you got to get the file list to an array. You can do this by using below command

Directory.GetFiles(“YourFolderPath”)

This will get all the files into an string array.

Now, use a For Each activity and loop through the array item. Each item will have its full path.

within the loop, get only the file name from the path and assign it to some variable
Path.GetFileName(item.ToString)
Now you have a string variable that holds only the file path in each iteration. Now you can do a split from the so that you can get only the first segment of the file.

FileName.Split(" "c)(0).ToString

5 Likes

Hi @Palaniyappan Thanks for your quick response.
I have three format, how can I give together.
doc, docx, rtf
Like you have given *.pdf

@balkishan

If your file name is five digits then you can use regex in “is match” activity.
In “ismatch” activity Input you can give item.tostring and in regex place you can give as “\d{5}”.

Result is boolean, so if it’s true you can move your file.

Hope this helps

Thanks,
Aman

1 Like

unless you have unwanted files in the folder, use of below will give you all the files in the folder.

Directory.GetFiles(“YourFolderPath”)

2 Likes

How can I give more formats here like doc, docx, and tif etc.
image

2 Likes

Fine in that case we can use instead of the above like this
out_filepatharray = Directory.GetFiles(“yourfolderpath”)
then use a for each loop and pass the above variable as input and change the type argument as string
–inside the for each loop use a if condition like this first
**item.ToString.Contains(".doc") or item.ToString.Contains(".docx") or item.ToString.Contains(".rtf")
if this condition gets passed it will go to THEN part where we can another another condition like this
item.ToString.Contains(“10001”)
And if this condition pass goes to THEN part and use move file activity

Cheers @balkishan

2 Likes

Hi @balkishan

  1. declare one collection variable
  2. write three for loops to get each format files and use add to collection activity to add it to a collection variable

ex:

1

repeat it for the remaining two formats then your collection variable will contain required format files then process each file how you want.

I did like you said, but it’s not moving the profile, UniqueId is working fine I checked with the write activity.
It’s not touching the move file activity.
image

2 Likes

is it going to THEN part of inner if condition with condition
item.ToString.Contains(in_UniqueID)
Check with a write line before that move file activity and mention like this in write line activity
item.ToString

Cheers @balkishan

2 Likes

It’s not going into the then part bro. It’s itirate three times as I have 3 files in the folder but not going into the then part where I used the Move activity.

Fine before the inner if condition placed in the THEN part of first if conditon
use
–a write line activity and mention as item.ToString
and another writeline activity and mention as in_UniqueID
–and then place the if condition in the THEN part with condition like
item.ToString.Contains(in_UniqueID)

this is done to check whether the item, the string is getting validated correctly or not with the first condition and to check the value of them and unique id as well

Kindly share that screenshot of that output buddy
Cheers @balkishan

2 Likes

for first if condition it’s going but for second if condition it’s not going into the Then part.

@Palaniyappan

yes buddy the values are different right
we dont have 10003 in the string TestResume\10001\sample1.pdf
so that why it didn’t go to THEN part
@balkishan

2 Likes

Thanks @Palaniyappan @Lahiru.Fernando @aman_sheik resolved.

3 Likes

Great
Cheers @balkishan

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