Rename files in a folder appending the folder name to the front of the file name

I have 62 folders and dozens of files coming each day to each folder. I need to append the folder name to the front of the file name. for instance folder B0 has a dozen files in it. I need to add B0- to the front of each file in the folder.
I need to do this before moving the file as I also have a process to write the file names to a csv.

Fine
hope these steps would help you resolve this
–use a assign activity like this
arr_directory = Directory.GetDirectories(“yourfolderpath”)
where arr_directory is a variable of type array of sstring
–now use a FOREACH activity and pass the above variable as input and change the type argument as string in the property panel
–inside the loop use another assign activity like this
arr_files = Directory.GetFiles(item)
where arr_files is a variable of type array of string

–now within this current for each loop use another FOR EACH activity and change the name of the variable from item to files and pass the input as arr_files and change the type argument as string in the variable panel

—inside this inner for each loop use MOVE FILE activity and mention like this
in path property files.tostring and in destination property mention as
item+“\”+Split(item.tostring,“\”).last.tostring+“_”+Path.GetFilenamWithoutExtension(files)+Path.GetExtensions(file)

Cheers @covcreo

1 Like

really new to this can you show me in an xaml?

1 Like

were we facing any issue in those steps buddy
i would be happy and love to see you try once from your end…because you would come to know lot of stuffs…while simulating this process…
we can get all the activities from activity panel as well
kindly let know for any queries or clarification if you are facing any difficulties with this
Cheers @covcreo

1 Like

yeah I know nothing about loops

one or more children have validation errors or warnings.

Simple.
1)drag and drop for each activity (we will call it “for each 1”).
2)use Directory.GetDirectories(“folderpath”) in “for each 1”
declare one string var “folderName”
folderName= items.ToString.split(“"c)(items.ToString.split(”"c).length-1)
3)use one more for each activity (we will call it “for each 2”) inside “for each 1”
4)use Directory.GetFiles(item.Tostring) in “for each 2”
declare one string var “fileName”
fileName=path.GetfileName(item.ToString)
5)drag and drop Invoke Method activity inside “for each 2” and set it as below:
TargetType= Microsoft.VisualBasic.FileSystem
TargetObject= leave it as it is
MethodName= Rename
Parameters:
1) In String Item.ToString (inside “for each 2”)
2) In String Item.ToString.Replace(fileName,folderName+“-”+fileName)

I hope this will work for you!

ok going through the list
I assume the 1. is assign

and should say

foldername = Directory.GetDirectories(“servername\d_box_1$\A0”) in “for each 1”foldername

I am getting value not supported

Give the file path
Example: D drive or C drive ( drive name, folder name, file name)

OK I’ve given up on the loop as I do not yet have enough information to understand what to put where. but, I have created a power shell script that does the renaming of the files in the folder. It works in power shell but, when I set it to invoke in UiPath I get an error. Again I am using this in power shell >(GCI \\my-server-name\d_box_1$\A0\*.pdf) | Rename-Item -NewName {$_.Name -replace "^","A0-"} When I place it in Invoke powershell i get the error below.
image
What am I missing on the expression? What do I need to add for UiPath that works perfectly fine in power shell?

After some work I was able to resolve the PowerShell issue. It was set by default to system.management. changing to string resolved the issue.

Still no closer to loping though. a visual would have been nice.

(upload://1kYurBmbDQ4v3v7569TCQ3lPduU.png)

image

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