您的位置:程序门 -> .net技术 -> vb.net



怎樣可以取到一個文件夾的大小?在線急.................50


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


怎樣可以取到一個文件夾的大小?在線急.................50
发表于:2007-06-14 20:07:23 楼主
怎樣可以取到一個文件夾的大小?
我想判斷這個文件夾里面的內容是否有改變,所以想知道文件夾的大小

各位高手請指點下
发表于:2007-06-14 20:27:341楼 得分:0
filesystemwatcher控件就能实现你的功能,何必那么麻烦,性能还不一定好:


imports   system.io
public   class   form1

        private   sub   form1_load(byval   sender   as   system.object,   byval   e   as   system.eventargs)   handles   mybase.load
                filesystemwatcher1.path   =   "d:\temp "
                filesystemwatcher1.notifyfilter   =   io.notifyfilters.attributes   or   io.notifyfilters.creationtime   or   io.notifyfilters.directoryname   or   io.notifyfilters.filename   or   io.notifyfilters.lastaccess   or   io.notifyfilters.lastwrite   or   io.notifyfilters.security   or   io.notifyfilters.size
                addhandler   filesystemwatcher1.changed,   addressof   onchanged
                addhandler   filesystemwatcher1.created,   addressof   onchanged
                addhandler   filesystemwatcher1.deleted,   addressof   onchanged
                addhandler   filesystemwatcher1.renamed,   addressof   onrenamed
                filesystemwatcher1.enableraisingevents   =   true
        end   sub
        private   shared   sub   onchanged(byval   source   as   object,   byval   e   as   filesystemeventargs)
                '   specify   what   is   done   when   a   file   is   changed,   created,   or   deleted.
                console.writeline( "file:   "   &   e.fullpath   &   "   "   &   e.changetype)
        end   sub

        private   shared   sub   onrenamed(byval   source   as   object,   byval   e   as   renamedeventargs)
                '   specify   what   is   done   when   a   file   is   renamed.
                console.writeline( "file:   {0}   renamed   to   {1} ",   e.oldfullpath,   e.fullpath)
        end   sub

end   class
发表于:2007-06-15 09:31:442楼 得分:0
directory.getfiles(target).length
发表于:2007-06-15 09:36:023楼 得分:0
文件夹大小不变并不代表文件没有发生变化

filesystemwatcher监视文件夹,接受事件通知是比较好的解决办法
发表于:2007-06-15 09:46:234楼 得分:0
filesystemwatcher可以,只是filesystemwatcher也有自己的弊端


快速检索

最新资讯
热门点击