Move file from one to another folder

I have multiple types of files in a folder, I want to fetch only pdf and moved in a seprate folder. I am using the below approach, but I don’t see the option where I have to pass a this pdf loop variable. or any other approach better than this, plz guide.
@Palaniyappan plz guide

3 Likes

You can get by this Buddy
Outfilepath = Directory.Getfiles(“yourfoldername”,"*.pdf")
Then use this in for each loop @balkishan
And simply use move activity and pass the variable item as source path and
Destination as your path you want
Cheers @balkishan

1 Like

Yes I did this, but in the loop part what I have to do, as I used move activity in this there is only two option from and destination folder path. I don’t see the option where I have to pass pdf varable.

2 Likes

There is a property called FROM
There mention as item, the variable that we obtain from for each loop
And in DESTINATION… mention tye path where you want to move
Cheers @balkishan

1 Like

@balkishan, in destination path you can use your pdf variable. It will rename the file with your variable name.

1 Like

Did that work Buddy
Cheers @balkishan

1 Like

@balkishan

Mention this in Move File activity.

From - Path: pdf

To - Destination: “Destination FolderPath”

1 Like

@balkishan Refer This

1 Like

I’ve to move the word also so can I can give both the extension at same time?

2 Likes

@balkishan

Is the folder contains only PDF and Word files ? And also you want to move all files in that folder ?

If yes then

String files [ ] = Directoty.Getfiles(“FolderPath”)

2 Likes

Aaah…we need another loop with same steps…but in directory.getfiles(“yourfolderpath”,"*.docx)
Only if the folder has those type of files then you can simply mention like
Directory.getfiles(“yourfolderpath”)
Cheers @balkishan

1 Like

It’s containing multiple files images also, png jpeg, pdf, doc, docx like this
so I have to move the pdf and the docx files only.

2 Likes

Bro can’t we use in the same loop? If we give this extension one by one,

Like this image

we can use two loop but it better if we use one loop only.

1 Like

Then we need a separate loop buddy @balkishan
As suggested earlier @balkishan

1 Like

Buddy, only two arguments can be passed for getfiles method…
Foldepath and filepath
Cheers @balkishan

Simply use if condition inside the loop. If name contain your extension (like .pdf), then use move file activity in the Then block. It will move only files you want.

TanQ,
Mic

1 Like

@balkishan

Yes no need of two loops and we can do it with one loop only.

  1. String files = Directoty.Getfiles(“FolderPath”)

  2. use For Each loop to iterate that array of files.

                             ForEach item in files
                                  if item.ToString.Contains("pdf") or item.ToString.Contains("docx") or 
                                     item.ToString.Contains("doc")
                                 Then:
                                      use **Move File** activity and mention below.
                                                  From - Path: item
                                                  To - Destination: “Destination FolderPath”
2 Likes

@lakshman it’s not going into the move activity, It contains the all files in a folder and it just touch the if area but not going into the Move activity?

image

@lakshman If you see this now it’s on the if activity but not going into the then part
image

3 Likes

Fine we can try with a if activity…
The condition should be like this buddy
Item.ToString.contains(".pdf") or Item.ToString.contains(".docx)
Don’t put star before dot… Cheers @balkishan

@balkishan

It should be like this: Contains(“pdf”) or Contains(“docx”) or Contains(“doc”)

2 Likes