Check file size on an attachment

Does anyone knows or have an sample of a bot on how to check the file size of an attachment? The attachment file is in txt format.
BalaReva.Externals package allows the Bot to check the file size BUT this package is not installed yet in our Orchestrator trial/production environments.

Thanks!

I’m not sure how to do this directly with an attachment, but if you use Save Attachments, then you can use the filepath that is returned in the Output property.

the vb.net way to get filesize is like this:
New FileInfo(filepath).Length
image

Since you will be dealing with a list of files, you need to either use LINQ or a ForEach to grab the file you want out of the list, or hardcode the first item.
New FileInfo(attachments.First).Length

You could test it with the attachment directly but I am not sure that would work, like this:
New FileInfo(mailmsg.Attachments(0)).Length
You’ll need to research if that is possible.

But, if you use the Save Attachments activity to output the attachments to a list of filepaths, then use what I mentioned above using System.IO.FileInfo()

Regards.

1 Like

i need some help…regarding
to find file size in uipath…i need to write expression for file size and file format

1 Like

Provide some more info please, like what you have tried or any errors you have gotten.

Refer to my previous post, as it shows exactly how to get the file size of a filepath. Also, notice in the image that there are other items that can be used like LastWriteTime etc. Additionally, you can use System.IO.Path. or System.IO.Directory. and it will show a list of other items you can get from a filepath. Please test this in a Write Line or Message Box, and you can see all the information you can get from a file.

Regards.

image i need to upload a file under this requirements…

i used get file folder, write line

For one file, you can do this:
filePath = "filepath"
fileSize = New FileInfo(filePath).Length
fileType = Path.GetExtension(filePath)

For multiple files, just replace the filePath assignment with a .GetFiles() and ForEach
ForEach filePath In Directory.GetFiles(directory)

Refer to images below for more options that you can use…
image
image

Regards

1 Like