1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 'Dim returnValue As String() Dim fp As New FileIOPermission(PermissionState.None) fp.AllFiles = FileIOPermissionAccess.AllAccess 'returnValue = System.IO.Directory.GetFiles(path, searchPattern, searchOption) Dim d As IO.DirectoryInfo Dim f As IO.FileInfo Dim regExpObj As New Regex(searchPattern) If path.LastIndexOf("\") = 1 Then path = path Else path = path & "\" End If Dim ofs As New IO.DirectoryInfo(path) For Each d In ofs.GetDirectories 'directorylist 'MsgBox(path & d.Name, MsgBoxStyle.MsgBoxHelp) If d.Name <> "System Volume Information" And d.Name <> "$RECYCLE.BIN" And d.Name <> "Windows" And d.Attributes <> IO.FileAttributes.SparseFile Then For Each f In d.GetFiles If regExpObj.IsMatch(f.Name, RegexOptions.IgnoreCase) Then fileList.Add(path & d.Name & "\" & f.Name) End If Next If searchOption = IO.SearchOption.AllDirectories And IO.Directory.Exists(path & d.Name) Then searchFileSystem(path & d.Name, searchPattern, searchOption) End If End If Next Return fileList End Function |
oke... ga ik naar kijken..quote:Op zondag 23 september 2007 16:08 schreef Detroit het volgende:
a) Het beste kun je exceptions afvangen door te beginnen met de meest specifieke exceptie en te eindigen met de meest algemene exceptie (volgens mij System.Exception)
zoals je kan zien is de lijst nu hardcoded in het programma, dit wil ik los hebben in bijvoorbeeld een array (die ik via de gui weer kan aanpassen, mappen toevoegen c.q verwijderen)quote:b) Hoe bedoel je soepeler aangeven?
hmm oke...quote:c) Geen verstand van Vista...
d) Denk dat daar vast wel iets van libraries voor zijn.. Geen idee hoe je dat handmatig moet doen, waarschijnlijk een aantal bytes in een byte-array gooien en op een bepaalde locatie kijken naar de waarde...
de grootste probleemgever is de SecurityException (o.a. op mappen in de windows folder, daarom nu ook geexclude) en onder vista de Link-point van Documents and settingsquote:Op zondag 23 september 2007 16:16 schreef dikkedorus het volgende:
Link-points zijn idd lastig, ik heb er nog niet mee gewerkt. Het is een integraal deel van NTFS, dus volgens mij moet het ondersteund worden door de api die je gebruikt. Google er eens op zou ik zeggen.
Welke excepties krijg je? Zoals Detroit al zegt zou je afvangen moeten doen van meest specifieke naar meest algemene, zodat je je eigen handlers kan schrijven voor de excepties waar je wat mee kan, en dat je globale excepties (I/O errors e.d.) gewoon afhandeld door je programma te stoppen, critical termination oid..
vind em al bijzonder rapquote:Op zondag 23 september 2007 16:39 schreef SuperRembo het volgende:
Waarom gebruik je eigenlijk de searchoption niet in de GetDirectory method? Als je dat wel doet dan hoef je je searchFileSystem functie niet recursief aan te roepen. Dat is een stuk sneller.
het gaat voornamelijk gebruikt worden voor 1 of 2 lagen diep en de hoeveelheid? geen idee, ik gok per dvd max 100 bestandenquote:Op zondag 23 september 2007 17:44 schreef SuperRembo het volgende:
De grootte van de bestanden doet er in dit geval niet toe, wel het aantal bestanden en mappen en hoe diep de mappen genest zijn.
Daarnaast is het gewoon stom om zo'n handige optie niet te benutten
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | excluded.Add("System Volume Information") excluded.Add("$Recycle.Bin") excluded.Add("Recycle Bin") excluded.Add("$RECYCLE.BIN") Return excluded End Function Function searchFileSystem(ByVal path As String, ByVal searchPattern As String, ByVal searchOption As IO.SearchOption) As ArrayList If excluded.Count >= 1 Then excluded.Clear() End If excluded = fill_arraylist() excluded.Add(Environment.GetEnvironmentVariable("windir").Substring(3)) excluded.Sort() Dim d As IO.DirectoryInfo Dim f As IO.FileInfo Dim Regexp As New RegexOptions Dim dirs As New IO.DirectoryInfo(path) Dim files1 As Array = dirs.GetFiles("*") For Each f In files1 If Regex.IsMatch(f.Name, searchPattern) Then files.Add(f) End If Next For Each d In dirs.GetDirectories() If excluded.BinarySearch(d.Name) < 0 Then Console.WriteLine(d.FullName) If Not CBool((d.Attributes And IO.FileAttributes.ReparsePoint)) Then If searchOption = IO.SearchOption.AllDirectories Then searchFileSystem(path & "\" & d.Name, searchPattern, searchOption) End If End If End If Next Return files End Function |
1 |
|
Forum Opties | |
---|---|
Forumhop: | |
Hop naar: |