To delete all .docs files of today's date from download folder

Hi All,

I want to delete all files which are downloaded with today’s date in docx format. What will be the full expression where start date is today’s date and it should delete all files downloaded today

@marina.dutta,

Code this using Studio.

folderPath = "C:\YourDownloadPath"
docxFiles = Directory.GetFiles(folderPath, "*.docx")

For Each file In docxFiles
    If File.GetCreationTime(file).Date = DateTime.Now.Date Then
        File.Delete(file)
    End If
Next

Thanks,
Ashok :slight_smile:

1 Like

Hi @marina.dutta

Use the below code in Invoke Code

(Directory.GetFiles("C:\Your\Directory\Path", "*.docx").
 Where(Function(f) File.GetCreationTime(f).Date = DateTime.Today).
 ToList().
 ForEach(Sub(f) File.Delete(f)))

Hope it helps!!

1 Like

@Parvathy

getting some syntax error.


Hi @marina.dutta

Use below code in Invoke Code:

Directory.GetFiles(path, "*.docx").
    Where(Function(f) System.IO.File.GetCreationTime(f).Date = DateTime.Today).
    ToList().
    ForEach(Sub(f) System.IO.File.Delete(f))

Invoked Code Arguments:

Regards

Hi @marina.dutta

You can do it the below way also:

=> Use below syntax in Assign:

Assign activity -> fileList = Directory.GetFiles("C:\Your\Directory\Path", "*.docx").Where(Function(f) File.GetCreationTime(f).Date = DateTime.Today).ToArray()

fileList is of DataType Array(System.String)

=> Use For Each loop to iterate through fileList

For Each currentText in fileList
     Delete File activity -> pass currentText
End For Each

Regards

@ashokkarale @Parvathy

Thanks to both of you for the solution

1 Like

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