Move file to most recent directory

Hello everyone!

I create a new folder each month with the name of the mont (inside another folder) to store some Excel files that I download. Right now I have an automation that moves that Excel from the downloads folder to the folder that I choose, but I have to update the folder manually each month from StudioX. My question is: is it possible to move that downloaded file to the newest subfolder created so I dont have to update the destination folder manually each month?

I hope I explained the problem correctly.

Thanks in advanced for any help!
Carlos.

Hi! @ccastrejsan ,

Instead of download the folders to download folder you can create the new folder and in that folder you can download the file directly.

Follow the below steps…

Take one Assign activity FolderPath= C:\Users\

  1. Take one create folder activity give the path example:
    `

FolderPath+DateTime.Now.ToString(“dd-MM-yyyy hhssmm tt”)

`
This will creates the SubFolder

  1. After clicking the download icon from chrome. The Explorer window will appear. Use attachwindow and take one typeinto pass the FolderPath+FileName Like this

`

FolderPath+DateTime.Now.ToString(“dd-MM-yyyy hhssmm tt”)+FileName

`

That’s it.

Regards,
NaNi

1 Like

@ccastrejsan,

Try with this query to get the latest updated folder from a directory

Directory.GetFiles("yourPath").[Select](Function(x) New FileInfo(x)).OrderByDescending(Function(x) x.LastWriteTime).Take(1).ToArray()
1 Like

Where can I use this query? I suppose there is an activity where I can store the result of that query into a variable and then use that variable to store the file there?

Thanks for your answer!

@ccastrejsan ,

Use Assign activity, this query should come in the value property of the Assign activity

1 Like

One more question, what should be the type of the variable? Thanks for your help!

@ccastrejsan,

Variable should have List(Of string) type

1 Like

If I try your solution it gives me this error.

Main.xaml: Cannot assign from type ‘System.Object’ to type ‘System.String’ in Assign activity ‘Set Variable Value’. You cannot convert a value of type ‘1-dimensional array of System.IO.FileInfo’ to ‘1-dimensional array of String’ because ‘System.IO.FileInfo’ is not derived from ‘String’.

@ccastrejsan,

Check this workflow
FileList.xaml (5.6 KB)

1 Like

Hi! Thanks for all your help.

I cannot open it as I am using StudioX insteado of Studio.

@ccastrejsan,

Check this screenshot.

1 Like

Thanks! When I run it it looks like it works, but once the proccess is finished, it seems that the file has not been moved. These screenshots show the workflow.
The values of the variables are exactly as the sreenshot you sent me.



@ccastrejsan,

This “strRecentFolder” variable will hold only the recent folder name, so you need to add the path with this to move the file to the correct directory.

I think now in your process folder a new folder might have created and the files are moved to it I guess.

Use Path.Combine(“Your Directory Path”, strRecentFolder) in the Move file activity’s “To” value.

1 Like

That worked! Thanks for all your help!

1 Like

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