I have to get previous created folder

Hi all, My BOT generated daily back folder but I have to get previous Created folder from my backup folders

Any one please

Thanks
Shaik Muktharvalli

Hi @shaik.muktharvalli1

This expression would get you the latest file

Str_Path = Directory.GetFiles(yourfolder_path,“*.xlsx”).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Tolist(0)
Directory.GetDirectories("yourdirectorypath").[Select](Function(d) New DirectoryInfo(d)).Where(Function(d) d.CreationTime.Date.Equals(Datetime.Now.Date)).ToList()

Regards
Gokul

1 Like

Hi @shaik.muktharvalli1

  1. Get Current Date:
    Use the Now function to get the current date. Assign this value to a variable, e.g., currentDate.
  2. Calculate Previous Date:
    Subtract one day from the current date to get the previous date. You can do this using the AddDays function.
   Assign activity:
   previousDate = currentDate.AddDays(-1)
  1. Format Date as String:
    Convert the previous date to a string with the desired format (e.g., “yyyyMMdd”). You can use the ToString function for this.
   Assign activity:
   previousDateString = previousDate.ToString("yyyyMMdd")
  1. Build the Path to the Previous Backup Folder:
    Assuming that your backup folders are named using the date (e.g., “Backup_20231011”), you can now construct the path to the previous backup folder by concatenating the folder base path and the previousDateString variable.
   Assign activity:
   backupFolderPath = "C:\YourBackupBasePath\Backup_" + previousDateString
  1. Check if the Folder Exists:
    To ensure that the folder exists before accessing it, you can use the Directory.Exists function. If the folder exists, proceed with your backup operations.
   If (Directory.Exists(backupFolderPath)) Then
       ' Access the previous day's backup folder
   Else
       ' Handle the case where the folder does not exist
   End If
  1. Access the Previous Backup Folder:
    Within the “If” block where the folder exists, you can perform any operations needed on the previous day’s backup folder.

Hope it helps!!

Hi @shaik.muktharvalli1

backupFolder = "C:\YourBackupFolder"
out_backupFolder = Directory.GetDirectories(backupFolder).OrderByDescending(Function(x) DateTime.ParseExact(Path.GetFileName(x), "yyyyMMdd", CultureInfo.InvariantCulture)).FirstOrDefault()

not latest file , i have to get previous latest folder

Check out this? @shaik.muktharvalli1

for your calrity

image

I have to get previous updated folder ( In image one folder generated 8:38AM and another one generated 8:39AM) then I have to get previous one means 8:38AM folder

Hi @shaik.muktharvalli1


Folders=Directory.GetDirectories("C:\Users\lrtetala\Documents\UiPath\BlankProcess12\New folder")

SortedFolders=Folders.OrderBy(Function(dir) New DirectoryInfo(dir).LastWriteTime).First

Hope this helps!!

Check out this thread @shaik.muktharvalli1

@shaik.muktharvalli1

Please check on this xaml

BlankProcess12.zip (55.2 KB)

Cheers!!

can you vaibales type please

can you show vaibales type please

@shaik.muktharvalli1

@shaik.muktharvalli1

Here is the latest folder

please run this subfolders then i have to get “New Folder 2” because its previous updated folder

@shaik.muktharvalli1

Try this

Please find the below xaml

BlankProcess12.zip (57.4 KB)

Hope this helps!!

@shaik.muktharvalli1

Folders=Directory.GetDirectories("C:\Users\lrtetala\Documents\UiPath\BlankProcess12\New folder")

SortedFolders=Folders.OrderBy(Function(dir) New DirectoryInfo(dir).LastWriteTime).ToArray()

MsgBox:SortedFolders(1)

Not working bro…it taking another folder not take excepted folder

@shaik.muktharvalli1

Can you share screenshot of your process workflow or xaml because it is working for me

Once confirm the below result you wanted