Delete only hidden files in folder

Hey! I need to delete only the hidden files in a folder (if there is). There’s more than 20 folders, so I need to loop through the folders and delete the hidden files. I don’t see a way to filter the folders.

Do you have a way to do it ?

to find only the hidden you can use code like this:

Dim directory As New DirectoryInfo("D:\Apps\Hidden")
Dim hidden_Files As FileInfo() = directory.GetFiles(). _
                                 Where(Function(file) (file.Attributes And FileAttributes.Hidden) <> 0).ToArray()

Dim hidden_folders As DirectoryInfo() = directory.GetDirectories(). _
                                        Where(Function(dirs) (dirs.Attributes And FileAttributes.Hidden) <> 0).ToArray()
1 Like

Hi @jadbenn

You can use this custom activity that allows you to extract all the properties of a file including its hidden status… Through this you can find the files that are hidden easily…

1 Like

Hi @jadbenn
For each folder you want to check, have a for each loop to return all the files in the directory, for example: ForEach item in Directory.GetFiles(“Path\To\Folder”)
Then for each item, assign it to a new variable of type FileInfo.
Once you have done this you can use the following line to find out if that particular file is hidden or not:
FileInfoVar.Attributes.HasFlag(FileAttributes.Hidden).ToString

Hope this helps!

1 Like

Hi @Cona,

Thanks for the solution, but when I’m assigning item to FileInfoVar, one is a String and the other FileInfo Type, no?

Yes you are right @jadbenn, when assigning you will need to do it like this:
FileInfoVar = new FileInfo(item)

That should convert it to the correct type for you.

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