Move a file or Rename a file

I am trying to insert the following senetence
file.move(oldpath,newpath)

But I don’t know which activity I must use because I tried to use “Assign” but It is shown a windows “Expresion does not produce a value”

Which activity Can I use to Move a file?

Is there a way to Rename a file?

I don’t see in the options the method “Rename” for a file

3 Likes

Hi Lucky
Please follow below steps
Activity Name :Invoke Method
Target Type : Microsoft.visualbasic.filesysytem

MehtodName :Rename

Go to Properties of Invoke method
Parameters:
Direction—Type-- -Value
-----In------- string – “OldFilename.txt”
-----In------- string – “NewFilename.txt”

Thanks
Udaykumar

7 Likes

There’s a MoveFile activity that does just that, no need for InvokeMethod.

For Renaming you “move” the file to the same folder, just with a different name.

As a sidenote - I’d recommend using System.IO.File type, method name Move instead of Ms.VB, since it doesn’t rely on VB specific implementation.

Regards.

11 Likes

Thanks!!

In fact, I did that, I hat to move the file to the same folder but renaming it

hey @Lucky0906

as @andrzej.kniola said

For Renaming you “move” the file to the same folder, just with a different name.

it will do what you wants.

To move a file from one destination to other destination with a different name then just rename the file when filling in the destination path

MoveFileWithRenameUsiNgMoveActivity.xaml (4.3 KB)

Regards…!!

7 Likes

The file name that I need to rename is not static. It changes daily.

How do I specify a wild card in the file name using the “Path” field in the “Move File” activity?

BoCoNdOn,

In a similar case I found it easier to create a MSDOS batch file to move files using wild cards. You need to use StartProcess activity to call the batch file with the MSDOS commands.

Hope it helps

@BoCoNdOn What is the naming convention of your file?

you can always get the files by wildcard character using below logic

Directory.GetFiles("C:\Users\xyz\Desktop\files","DailyFile_*.txt") //DailyFile_040716.txt

1 Like

If you move a file or Rename a file you can use my software BatchRenameFiles Tool . It’s very easy to use .

Good Job

its giving error that filesystem dose not contain rename method.

MoveFile Activity will help you in this .

Use the properties as below

From :- Path\Filename
Destination :- Path\RenamedFilename

1 Like

Hi Uipath angels,

Can I get a .xaml sample about how to handle case below?
The requirement is to find target file, change file name with not static string and move all of them to another folder.

The oringinal data is like following.
※※※In a word you can regard the first file name as title in each set, get the string between “~_00” and “.txt” and insert it into the place where “a,b,c,d,e,f,g” are.

20181202_HL00431_00_3837_000_000_name.txt
20181202_HL00431_01_a.txt
20181202_HL00431_02_b.txt

20181202_HL00441_00_3803_001_020_name1.txt
20181202_HL00441_01_c.txt
20181202_HL00441_02_d.txt

20181202_HL00555_00_3803_001_020_name1.txt
20181202_HL00555_01_e.txt
20181202_HL00555_02_f.txt
20181202_HL00555_03_g.txt

Hi,

Could you please advise how to move files with in FTP location

Hi @Ashwini_Kumaran what you can do is download the files from FTP server to your local server and then upload them to the location where you want them.