Move File from one folder to another in uipath studio activities

Can Anyone help me on move file path activity in studio. I used it before but for this usecase it is showing me an below error. studio activities
image

Hi @pari_patel
can u show the filepath please?

Sure. I want to keep first 8 characters as it is and rest of the characters will be change for each file. Also I want to move file with rename. Thanks in advance @NIVED_NAMBIAR
image

Path would be download folder path on windows.

Hi @pari_patel
i think that is reason for the issue

so better way is filter the file path based on patterns in file name

for eg , folder_1 is the path of folder where the file is present

now use assign activity

file_list = Directory.GetFiles(folder_1).Where(Function(file) System.Text.RegularExpressions.Regex.Matches(Path.GetFileName(file).ToString,“rc4jg3w_*”).Count<>0)

Now you will list of all files which matches the given file name patten

Regards,
Nived N

Thanks. Can you suggest another way? I am not able to get into this code.

Oh sorry

I forget to tell this shortest way to try out

U can try using this assign activitiy

file_list= Directory.GetFiles(folderpath,“rc4jg3w_*.txt”)

the file list will be list of all filepath whose file name had the Pattern as u specified

rc4jg3w_*.txt

Ok. Then for each activity need to use?
Actually we can do using move file activity only because there needs to rename file while putting on destination folder.

You can’t use wildcards in Move File. You’d need to do a For Each, with Directory.GetFiles(path + “\rc4jg3w_*.txt”) and within the For Each do the Move File.

thanks. Correct me where I am going wrong.

@pari_patel - Your ‘From’ should be ‘File’…

Get rid of the Assign and the source variable. Just put the Directory.GetFiles expression into the “in” box of the For Each.

Also, click the For Each activity and in its properties, change the datatype to string. Now file will have the path and filename of the file. This property being wrong is why you’re getting the “Illegal characters” error.

You just need to make sure Desti has the correct destination path and filename.

Destination path is correct and see below it is still showing me an error.
image

I used move file activity with one file and it’s working fine, but need to use wildcard as everytime file name should be different.

You don’t use a wildcard in the source path of the Move File. It doesn’t work that way. Disable the Move File activity and put in a Log Message activity so it’ll output the value of the file variable. Did you set the datatype of the For Each to string?

Sorry, I gave you an incorrect expression. It should be…

Directory.GetFiles(path,“rc4jg3w_*.txt”)

path should be just the path to the folder these files are in.

Thank You.
I used Directory.GetFiles(path,“rc4jg3w_*.txt”). It’s working.
Any luck on fid out the file rename while moved to destination?

Hi @pari_patel
you can store the file renamed name in a variable and then access by that way

do you mean file names in the destination folder ??

you can use same method as mentioned by @NIVED_NAMBIAR and @postwick but for loop with destination folder

follow below pseudo code

for each item in Directory.GetFiles(Destination_folder_path)
FileName = New FileInfo(item)
message box FileName.Name

variable FileName variable type is FileInfo (Browse for type System.IO.FileInfo in variables panel)

note that, to get file name we need to give FileName.Name (i.e. var_name.Name) and not FileName.ToString

hope this is helpful

2 Likes

Hello Pari,

As we can use you have mentioned *( asterisk sign) which is consider to be a special charactor and you cannot have a file path/file name with *( asterisk sign).

Please consider removing the *( asterisk sign) to avoid the error.

If you find this information useful than mark this as solution and hit like icon.

Thank you so much .

1 Like