|
Hi,
some facts:
1. file attributes are flags, several of them can be set at the same time, so your compare statements aren't going to cut it.
2. Windows, since Vista, is more protective about a number of files and folders, your old code is probably getting access violations.
what I do:
- copy everything you need in a big loop; inside the loop, have a try-catch, and log each individual failure.
- before copying, check for some special names and skip those.
- the exceptions will tell you which files you will have to skip, i.e. which checks to add to your code.
- and this will have to amended every time you move to the next Windows version...
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
On this fact:
"file attributes are flags, several of them can be set at the same time, so your compare statements aren't going to cut it."
I am seeing this when I follow via breakpoints, where it seems like several attributes are set. This makes sense to me.
Your suggestions:
- copy everything you need in a big loop; inside the loop, have a try-catch, and log each individual failure.
- before copying, check for some special names and skip those.
I like your suggestions, I just have a question. As far as tracking it to a log file, what attributes do you think I should catch that would be helpful to log? di.Attributes, di.fullname... anything else?
When you say special names, are you saying if I check fullname and the name of the recycle bin to a string I define "Recycle Bin ...". Is the name always consistent. We have several differnt servers 2000, 2003, 2008 and workstations are basically XP, Vista, and now 7. I assume the names might change between operating systems and the log will be helpful. I like this idea, but hoping you can clarify a little?
Thanks for your help!
Lost in the vast sea of .NET
|
|
|
|
|
KreativeKai wrote: what attributes ...?
just the name, attributes aren't relevant, they can change, e.g. when a backup is made.
KreativeKai wrote: special names...
check everything you ever encountered, do not change with the Windows version, just add to the skip list:
for (...) {
...
if (shortName=="Recycle Bin") continue;
if (shortName=="Trash Can") continue;
...
try {
....
} catch(...) {
....
}
}
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Thanks for all your help Luc! It is appreciated!
Below is the code I used in case anyone else can learn from it later when searching the message boards...
<br />
Dim di As DirectoryInfo<br />
For Each di In currentDirectory.GetDirectories()<br />
Dim strDirectoryName As String = di.Name<br />
Dim intFoundRB As Integer = strDirectoryName.IndexOf("$RECYCLE.BIN")<br />
Dim intFoundSV As Integer = strDirectoryName.IndexOf("System Volume Information")<br />
'Skip $Recycle.Bin or System Volume Information directories<br />
If (intFoundRB = -1) And (intFoundSV = -1) Then<br />
Try<br />
... Copy logic<br />
Catch ex As Exception<br />
... logic writing to log file for future reference if needed...<br />
End Try<br />
End If<br />
Next
Lost in the vast sea of .NET
|
|
|
|
|
On top of what Luc said, why are you even checking attributes?? Unless they determine eligibility of a file to be copied, you have no need to look at the file attributes. Your code snippet suggests that you're not using the attributes for anything at all, so I'd just remove the checks.
|
|
|
|
|
Hi Dave,
I was checking attributes because originally I was hoping to exclude the Recycle Bin and System Volume Information by skipping a system attribute, but found through testing that if I did an "if statement" with all the attributes it worked. Didn't make sense, but worked... Unfortunately from our intranet server, the copy was skipping those folders, so the logic was no longer sound.
You would think Microsoft would have a way of catching the recycle bin in the logic by looking for an attribute of some kind related to system files/directories?
Oh well, the logic worked by catching the name of the directories and skipping them that way.
Thanks for the feedback! Always appreciated!
Lost in the vast sea of .NET
|
|
|
|
|
For future reference, your code wasn't checking to see if any attributes were turned on. That IF statement you posted only returned True if one and only one attribute was turned on. Your check got lucky if it returned true.
You would normally check to see if a single bit flag is enabled like this:
If (di.Attributes And FileAttributes.System) = FileAttributes.System Then
|
|
|
|
|
Thanks for the clarification! It is evident now that I was misunderstanding the File.Attributes logic.
Lost in the vast sea of .NET
|
|
|
|
|
download the visual basic 6.0 softwear
|
|
|
|
|
VB 6 is a dead system. If you are interested in developing using Visual Basic then get a copy of the express version[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Dead system? Feh. "It has worked for ten years, we don't need to upgrade! Now, I need this list of changes implemented by tomorrow...."
|
|
|
|
|
"Good luck in finding 10 year old hardware with a 10 year old OS that still supports your platform. Better yet, try and get tech support from Microsoft, and don't forget to invite me when you try."
Either one moves on, or ones becomes obsoleted.
Bastard Programmer from Hell
|
|
|
|
|
Visual Basic 6.0 was never free.
However, it would be prudent you look at working in .Net instead of VB6 now.
|
|
|
|
|
Thanks, I won't, I just don't think so.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Go on, give it a try, you might like it.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Oh, but I have used it, in a previous century.
I did like it then, to some degree; I also am sure I won't like it today.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Luc Pattyn wrote: previous century
Previous millenium!
|
|
|
|
|
|
it's useless heritage, the ugliest program i ever saw.. what a waste of time..
|
|
|
|
|
Your words are true, but what can you do when your employer requests you to do so? Directly or indirectly: e.g. programs must run under Windows 2000 (our sales team just found a potential customer here in Germany (!) whose computers are still running almost all on Windows 2000) - guess how much fun it is to discuss your incapability to support such dinosaurs! When rich Germany is so far behind the times, how can you then expect an Indian to use a more modern programming language...
|
|
|
|
|
|
Did you ask the place you got it from? They would be in a better position to answer whatever question you have about it.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
That's specifically designed for VB6. It might work under VB.NET, but you'd be better off with an implementation that targets .NET.
Bastard Programmer from Hell
|
|
|
|
|
|
You're welcome
|
|
|
|