Solved

exclude hidden files

Posted on 2011-02-14
6
765 Views
Last Modified: 2012-06-27
I have this code in a loop.. but id like to exclude the hidden .doc files. Can someone imprve it?
 'add the doc files
                                For Each CurrentFileInfo As FileInfo In DirInfo.GetFiles()


                                    If CurrentFileInfo.Extension = ".doc" Then
                                        zip.AddFile(CurrentFileInfo.FullName)
                                    End If

                                Next


this code includes the hidden files with start of "~"
0
Comment
Question by:zachvaldez
  • 2
  • 2
  • 2
6 Comments
 
LVL 17

Expert Comment

by:paulop1975
Comment Utility
On the FileInfo class there's the Attributes property. Through it, yo may know if a certain file is hidden or not, among other things.
Hope it helps.
Cheers,
eLN
0
 
LVL 17

Expert Comment

by:paulop1975
Comment Utility
Hence, you would have somethong like this:
 
For Each CurrentFileInfo As FileInfo In DirInfo.GetFiles()
    If CurrentFileInfo.Extension = ".doc" And CurrentFileInfo.Attributes <> FileAttributes.Hidden Then
        zip.AddFile(CurrentFileInfo.FullName)
    End If
Next

Open in new window

0
 
LVL 33

Expert Comment

by:Todd Gerbert
Comment Utility
You need to change line 2 in above example to:

If CurrentFileInfo.Extension = ".doc" And Not CurrentFileInfo.Attributes.HasAttribute(FileAttributes.Hidden) Then


0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:zachvaldez
Comment Utility
to use hasattribute a namespace should be added. which one?
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 250 total points
Comment Utility
Sorry, it's HasFlag() not HasAttribute, and is only in .Net 4.  If you're at an earlier version of .Net try this:

If CurrentFileInfo.Extension = ".doc" And Not HasFileAttribute(CurrentFileInfo.Attributes, FileAttributes.Hidden) Then

Open in new window

Private Function HasFileAttribute(ByVal fileAttributes As System.IO.FileAttributes, ByVal attribute As System.IO.FileAttributes) As Boolean
    Return (fileAttributes And attribute) > 0
End Function

Open in new window

0
 

Author Comment

by:zachvaldez
Comment Utility
perfect!. I already got the system.io namespace. this work now
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now