Help for Copy

Goodmorning everyone…

I’m on my second day, using UiPath. Sorry for my banal request…

My job is:

  • Check if in a folder there are “.xlsx” files without the word “_filed” in the final part of the name
    and

  • if the condition is true:
    1: copy the file to the “archive folder” and adding today’s date in final part of name.
    2: rename the file as “_filed” in the main folder.

  • if the condition is false: do nothing.

Can anyone help me?

Hi

step 1 : get all the files in a folder using Assign FilesArr= Directory.GetFiles(folder_path,".xlsx",SearchOption.AllDirectories)
which will return an array

step 2 : Iterate through the filesArr using For each
step 2.1) Use an assign activity of string type to get fileName using the expression Path.GetFilenameWithoutExtension(item)

   Step 2.2) If FileName.Endswith("_filed")

inside Else block,
Use assign activity and rename the File and then ,
Use copy file activity and pass item as input and the folder in destination folder

Hope this helps :slight_smile:

2 Likes

Thanks friend.
I did not follow the same path, but a similar one.
Now I’m stopped here:

For now, after the two IFs I have only inserted MexBoxes to make sure it works.

However, the desired is for “ELSE”,

  • copy the file to another folder, adding today’s date to the end of the filename.

and to close:

  • Rename the initial file, as “namefile + _filed” in the same folder where it is originally located.

I think I have problems adding the date, but I’m reading a lot about this Community … Maybe … I can do it!!

:slight_smile:

Hi Aaron

I have done a sample workflow matching ur requirement , please lookinto this .

moveandRename.xaml (9.6 KB)

hope this helps :slight_smile:

Hello friends.
be patient … I have been on uipath for 3 days,
and I have no great programming notions. (I should do something else, but to live … I adapt myself).

So, I’ve read all your suggestions.
I downloaded and tried to adapt your scripts to my work.
I’m sure there is a more elegant and smooth way to get the result, but …
something happened.
First of all, I would like to say that I have changed the condition.
I no longer look for files that end with “_filed.xlsx”
but those that begin with “[Filed].” with any extension.
The goal is always the same.
Store these files, adding [Filed]. and today’s date.
(the date, at the beginning or at the end, is indifferent)

At the moment I’m stuck here:
image

Now, don’t be afraid of what I’m about to show:
This is my list of variables, Surely some double, useless, redundant … wrong … a real catastrophe …
(I will do cleaning at the end)… but it works. (almost).

I was able to copy the files, adding the word: “[Filed].” + Name + Extension
image

image
I get an error when I add the date.

RemoteException wrapping System.IO.DirectoryNotFoundException: Could not find a part of the path ‘C:\Users\aaron\Desktop\exx[Filed].06/08/2019 AAAA.xlsm’.


ToD is the variable, which should write today’s date. dd / mm / yyyy

assign value: Now.ToString(“dd/MM/yyyy”)
and in Type: String

After being unearthed, for the horror displayed in my script,
Can anyone help me?
I would like to add the date, which I specifically converted to String.
If I tell him to display it in a box, it works. Not here.

Next step, it will move these files, in “New folder”,
but, one step at a time.

Sorry for the excessively long post.

Hi @AaronMark,

I see you have almost completed the flow. Use

Path.GetDirectoryName(item) + “” + Path.GetFileName(item) + ToD + “.” + Path.GetFileExtension

If you still don’t get the issue fixed, please send the source code that you worked on, I can look into it and let you know how to fix the issue.

Hope this helps.

Are you sure you want to see so much horror? :roll_eyes::flushed::confounded::scream::crazy_face:

Really … I’m also disgusted by my script.
I’m sure there is a more elegant way … but ok …

thanks… very…
WooW.xaml (12.4 KB)

Hi @AaronMark,

I have made a few changes on to your workflow. I also checked for the standards. Below are the changes-

  1. Too many variables declared. Limited the variable count and deleted unnecessary once.
  2. Variable scope changes. Variables should always have to be declared in the scope that they are been used.
  3. Naming convention.
  4. Date format conversion logic. When you save a file, Windows will not let you have some special characters in it. one among them is ‘/’. So instead of converting the date format to DD/MM/YYYY, converting to DD_MM_YYYY.
  5. Declaration of source and destination folders. I have changed the source and destination folder paths. Please update it before running.

WooW.xaml (9.6 KB)

Hope this helps! Let me know if you need more details.

Thank you, you were very kind.
I check and try to understand the changes.

sure :+1:

I hope you have a lot of patience.
Anyway, thanks so far…

Ok … I understood the suggestion.

For variables, being a neophyte, I inserted them step by step, while writing and executing the script several times. I realized that some were useless, in fact.

For Variable scope…

  • OK. I memorize the information, and I treasure it!! :slight_smile:

For Date format…

  • My stupid head!! … aaarrrghhh!!

I will need a lot of practice, but the changes are understood to me.

Now there is another problem to be solved though.
It was already present in my script, and I only realized it now.
(If you want to tell me bad things,
this is the time to do it. :innocent::innocent::innocent::roll_eyes:)

ex: the contents of the “AAAA.txt” file in the source folder, is not modified, or overwritten.
The file is only completely replaced by another version, which could be “AAAA ver2.txt” or “BBBB.txt” etc …
Most of the time, only the final part of the name is changed, ie AAAA.ver2.txt AAAA.ver3.txt … etc …
Potentially, it could also be a new AAAA.txt file but with different contents. (Updated).

I need to keep the last current version, in the source folder,
and to make a copy of the previous one, in the “new folder” folder

To find the latest version from the previous one, in the source folder, my idea was when the Bot started:

  • search for “Field” files and delete them. (because now old, and already archived)
  • Rename files without “Filed” as “Filed”, and make a copy in
    “New forder” with the date of the filing day.

In your script, the file AAAA.txt is archived (ok, perfect), but left AAAA.txt in the original folder.
This means that the same file could be archived every time the bot is running.

I’m close to the solution … I think …
True?? :smile:

OK…
Resolved.

it was enough to enter the “delete” command
of the files containing the string “Filed”.

I would say that everything works.

Use Move file activity instead of Copy file.

Better is “file copy”…
I need to keep a copy in the source folder,
and a copy in the New folder.

I tested the job today… aaaaannnnddd… :expressionless:
Unfortunately, I realized that I was confronted with a new problem.

The BOT should run every 15.
Every 15 days, a new version of the file should be present, to be archived, in the New folder and replaced in the source.

But … if after 15 days, a new version is not loaded?
the BOT would continue to archive the same file, with the same contents, but with a different date.

It could be fine too … because in any case the latest version would still be present in the “source”, but it is not the best.

I’m thinking about working with the “creation dates” of the files.
The comparison will be made both with the creation date, and with the name present in the source folder.
Some idea?

The work done is to be discarded, but it was appreciated because I learned something from the suggestions.
(thank you so much).

To solve my problem, maybe I’ll work with dates.
Ok, I thought this:

  • creation of a .txt file where I write to each RUN, the current date.
  • the bot will enter the source folder, it will take the file creation dates.
    Those created with a higher date than the date written in .txt, will be left in source, the others, archived, with archiving date.

Yeah … I think it can work.
I put myself to work and at the limit, I will ask for help again.

Thank you all for your help.

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