How to check if particular file format is correct

Hi, I am handling one sharepoint automation . i need to check if below format file is present or not and it sould be in xlsx format
example - 2023-05-02_1269202_MembersListReport
format- YYYY-MM-DD_MemberGroupID_FileName.xlsx


as shown in the screenshot , in message box outlput i am getting 2023-05-02_1269202_MembersListReport . Now next step is i need to check file format

Hi @Neha_Aggarwal1

probably you’ll have to download the file and then check the file extension.

or else if you can Sync the Sharepoint to your machine, then maybe you can get the details of file such as extension.

i have to move the file into different folder after validate the file format

is there any other propert such as FullName on your FolderItem, or any property which might tell you about the extension?

in the folderitem.name itself i m getting as
“2023-05-02_1269202_MembersListReport.xlsx” … just i need to check the format for validation
YYYY-MM-DD_MemberGroupID_FileName.xlsx

we can use regex.isMatch or isMatch Activity for the filename pattern
e.g.
grafik

\d{4}-\d{2}-\d{2}_\d+_[A-Za-z]+\.[xX][Ll][Ss][Xx]

When it is only about the filetype extension we can do
grafik

can u plz tell without regex

Filetypeextension? or filename pattern? check without Regex

ohhh I thought you’re not getting the extension

You can simply check using this:

a.ToLower.EndsWith(“.xlsx”)

is there any specific date which would be written such as todays date or something?

If you need to check the whole formatting, then best option would be to use Regex that @ppr suggested

Thanks

both i need to check complete format date and extension
YYYY-MM-DD_MemberGroupID_FileName.xlsx

i need to check date also not only extension
YYYY-MM-DD_MemberGroupID_FileName.xlsx

no just the condition is date format should be YYYY-MM-DD_MemberGroupID_FileName.xlsx
it can be anydate

regex would be the preferred approach

For string base forcing an idea could be the following

  • replace the digits by a placeholder
  • replace the letter by placeholder
  • check pattern


in the input what i have to passed

[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

strPattern =
\d{4}-\d{2}-\d{2}_\d+_[A-Za-z]+\.[xX][Ll][Ss][Xx]

Assign Activity
isValid | Boolean =
System.Text.RegularExpressions.Regex.IsMatch(yourStringVar, strPattern)

here you can place the variable holding the file name value

you can use the shared Regex Statement line from above within the immediate panel and test it

Ensure that the valiable scopes are high enough
Use the isMatch activity
place below the isMatch activity a commment and set the breakpoint
then debug and check again in the debugging panels

After performing regex I got the result, now I have to check if this result is true means it’s in correct order then do move file .

How to check if result we got from regex.is match is true means in correct format?

With this method I got the result as u got in output but now I have to validate that this is the correct file format then do the move operation

My query is how to check if the result we got using regex is in correct format

Hi @Neha_Aggarwal1

The isMatch activity returns true or False in the output variable,

Just use an if condition and pass that boolean variable into it,
in the then section use the move File/Folder activity.
In the destination folder pass the destination folder path with the other properties as you need.

Thanks

Happy Automation! :smiley: