-
Oct 11th, 2015, 08:49 AM
#1
Thread Starter
Hyperactive Member
Cheking if a file exists
Hi ! I'd like to ask you a question about checking the existence of a file .
I have the following lines of code , conform which my program first tries to see if a specific file exists . Then , if the file does NOT exist , it will run the rest of the code (practically create the file) ; otherwise (if the file exists) there won't be anything for it to do :
Code:
If Dir(MyPath & "\MyFile.doc") = "MyFile.doc" Then
Dim AAA As String = "Hello World"
Else
Bla Bla Bla code to be executed
End If
In which MyPath and MyFile.doc are well known paths and files .
However , even when the file does NOT exist , my program does not run the specified code (the Bla Bla Bla code) . Why is that ? The funny thing is that the program fails to run the code in Win7 while in WinXP it runs as predicted ...
-
Oct 11th, 2015, 10:05 AM
#2
Re: Cheking if a file exists
The proper way to test whether a file exists is with the rather sensibly-named File.Exists method. The proper way to combine two partial paths is with the Path.Combine method.
-
Oct 11th, 2015, 12:47 PM
#3
Thread Starter
Hyperactive Member
Re: Cheking if a file exists
Thank you jmcilhinney .
I tried the File.Exists method , but unfortunately the program still fails to see that the file does NOT exist ...
How come in WinXP the program works fine while in Win7 it can't see the file is missing ? This is even weirder ...
One more thing , which probably is not related to my problem , but I'll ask just in case :
I was searching in the web and I found someone using the following code in order to see if his file exists :
Code:
If System.IO.File.Exists("C:\MyDocs\MyFile.txt") = False Then
Is it right ? I mean which method is the correct one to use ?
This :
My.Computer.FileSystem.FileExists
Or this :
System.IO.File.Exists
Edit :
Oh , OK , I just found this topic :
http://www.vbforums.com/showthread.p...ter-FileSystem
in which jmcilhinney already described that there is actually no difference .
So the main problem remains : why does the program fails to see that the file does NOT exist ?
Last edited by iliekater; Oct 11th, 2015 at 01:29 PM.
-
Oct 11th, 2015, 02:06 PM
#4
Re: Cheking if a file exists
Originally Posted by iliekater
So the main problem remains : why does the program fails to see that the file does NOT exist ?
What is the full path of the folder that you are trying to create your file in?
-
Oct 11th, 2015, 03:05 PM
#5
Re: Cheking if a file exists
It's clear that the file does not exist. Can you please post up the full path including an image of the directory path.
-
Oct 11th, 2015, 05:26 PM
#6
Re: Cheking if a file exists
Generally speaking, it's considered good practice to always look for a True result unless you have specific reason to look for False. If you're doing something if the file exists and if it doesn't then the most proper way to write the code would be:
Code:
If IO.File.Exists("file path here") Then
'File exists
Else
'File doesn't exist
End If
There is no reason that I'm aware of that that code should not differentiate between existent and non-existent files on any version of Windows. If it really doesn't on yours then something on your system is broken. I'm more inclined to think that it's user error.
-
Oct 11th, 2015, 06:19 PM
#7
Re: Cheking if a file exists
Originally Posted by jmcilhinney
There is no reason that I'm aware of that that code should not differentiate between existent and non-existent files on any version of Windows. If it really doesn't on yours then something on your system is broken. I'm more inclined to think that it's user error.
It could be user error, of course. However, when iliekater mentioned his code worked as expected on XP but "fails to see that the file does NOT exist" under Windows 7, I wondered if it might be file system virtualisation.
XP didn't have UAC in the way Windows 7 does. IN XP the user can quite happily create files in "protected" folders such as the Windows folder, the Program Files folder and the drive's Root folder. That's why I asked for details as to what his folder path actually is.
On Windows 7, if the user tries to write files to those folder, an UnauthorisedAccessException would most likely be thrown. However, to maintain backwards compatibility for applications written for older operating systems, UAC virtualisation is used. Under this system attempts to create a file under one of the protected folder paths are redirected to an equivalent folder in the user profile's \AppData\Local\VirtualStore\ path. I should note here that this only affects 32 bit apps.
As I learned from bitter experience a few years back, it is quite possible for your application code to create a data file in, say, your application's folder in Program Files (common practice in XP) and be telling you that a file exists there, but when you look there yourself in an Explorer window you'll not see the file because it's actually been created in the User profile\AppData\Local\VirtualStore\Program Files\<Program Name> folder.
Now all of this is usually controlled by the application's manifest file, and virtualisation is disabled by default. However, iliekater is using VB2008 and I think that VB2008 Express does not create a manifest file by default. Don't know about the full VS2008 editions.
Just a theory, but I think it's a possibility.
There's a fairly simple explanation here (not including the last paragraph).
Last edited by Inferrd; Oct 11th, 2015 at 06:30 PM.
-
Oct 11th, 2015, 06:59 PM
#8
Re: Cheking if a file exists
With one line of code, we can't really tell you what's going on. We need to know the path, and what you're trying to do, and why exactly you believe you're getting False when you should be getting True. Often, it turns out the code isn't doing what you think it's doing.
Personally, I don't use File.Exists() much if I'm working with the file. (I might if I have other reasons.) The filesystem is volatile. File.Exists() tells you the file was there at some particular moment, but anything else on the system could delete the file out from under you in the meantime. So it's never really safe to not expect a FileNotFoundException (though there are times when you can argue the risk is acceptable.)
I have a feeling if we had all of the information, Inferrd is on the right track. Windows really wants you to only be writing files to particular places. If you try to write to some of those, it can either fail miserably or try to "help" by relocating the file to a virtualized directory. But if not everything's in on the secret new location, you can believe the file's not there when it really is, or vice versa. If, like Inferrd suggests, you're using a 7-year-old copy of VB and expecting it to behave on a 3-year-old version of Windows the same way it did on a version that's no longer supported, well, you're asking for a lot.
But you haven't given us enough for us to do anything but throw random ideas at you. I want to see your code, and I want to see what you think it should do, and I want you to describe what it does. I keep saying this in a lot of threads: without those three things no one can help you except by happenstance.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Oct 12th, 2015, 06:00 AM
#9
Thread Starter
Hyperactive Member
Re: Cheking if a file exists
I think you are right . This is what must have happened . Windows is creating a virtual file or something .
The location I am trying to see if the file exists is c:\Program Files\Idea\Settings.set . In Win7 it's something different ; something like Programs (x86) , I can't remember right now because I don't have Win7 here .
The code that runs uses the OpenFile function to write into the file and thus also creating the file .
I found that there are two ways around . Either you must set the program to always run as Administrator or simply write the file in an arbitrary folder . However , if you know any other way to be able to write into the installation folder , that would be great .
-
Oct 12th, 2015, 06:12 AM
#10
Re: Cheking if a file exists
You should be writing to the AppData folder. That's what it's for. .NET provides methods to get such standard folder paths regardless of their location on the local machine.
-
Oct 12th, 2015, 07:34 AM
#11
Re: Cheking if a file exists
Originally Posted by Inferrd
It could be user error, of course. However, when iliekater mentioned his code worked as expected on XP but "fails to see that the file does NOT exist" under Windows 7, I wondered if it might be file system virtualisation.
XP didn't have UAC in the way Windows 7 does. IN XP the user can quite happily create files in "protected" folders such as the Windows folder, the Program Files folder and the drive's Root folder. That's why I asked for details as to what his folder path actually is.
On Windows 7, if the user tries to write files to those folder, an UnauthorisedAccessException would most likely be thrown. However, to maintain backwards compatibility for applications written for older operating systems, UAC virtualisation is used. Under this system attempts to create a file under one of the protected folder paths are redirected to an equivalent folder in the user profile's \AppData\Local\VirtualStore\ path. I should note here that this only affects 32 bit apps.
As I learned from bitter experience a few years back, it is quite possible for your application code to create a data file in, say, your application's folder in Program Files (common practice in XP) and be telling you that a file exists there, but when you look there yourself in an Explorer window you'll not see the file because it's actually been created in the User profile\AppData\Local\VirtualStore\Program Files\<Program Name> folder.
Now all of this is usually controlled by the application's manifest file, and virtualisation is disabled by default. However, iliekater is using VB2008 and I think that VB2008 Express does not create a manifest file by default. Don't know about the full VS2008 editions.
Just a theory, but I think it's a possibility.
There's a fairly simple explanation here (not including the last paragraph).
I hardly ever use it also but looks like you are correct. true if the caller has the required permissions
-
Oct 12th, 2015, 09:20 AM
#12
Re: Cheking if a file exists
Yeah, that's your problem.
Back in the day, MS was OK with people considering "Windows Security" to be the name of a traveling circus. But then people started losing money to viruses. And Macs started looking like viable threats.
So about 15 years ago, MS said a few things like "Stop writing files to Program Files, we won't allow it for much longer." Much like "Stop using VB6" or "Please consider Unicode", programmers didn't listen to Microsoft. What the heck would the writer of the OS know about what will and won't be supported? Lots of Very Big Applications like Lotus Notes Still require you to muck with your settings so they can continue to do things MS quit supporting before the current batch of high school graduates were born. MS was forced to write code that sort of made it work in a way that didn't let random viruses own your Program Files directory.
But you, well, you didn't know. MS doesn't publicize it too much today, and it doesn't help that a lot about .NET deployment encourages you to write things to the same directory as your binary. .NET is very bad about teaching you to be a good Windows citizen.
Anyway. You probably don't care about history. You want to fix your program.
From now on, if you want to save files, here's the directories you should consider:
- Ask the user. If it's data they're going to edit or open, let them put it wherever the heck they want. I have 20 folders in "My Documents" that I didn't put there, because the clowns writing whatever program decided that they should do things in a place called "My Documents", and it's the only place their program allows me to save/open data. Don't be a clown. People hate clowns.
- Use Environment.GetFolderPath(). This is a mini-lesson in itself.
Environment.GetFolderPath() is there to tell you where the system's directories live. You have to pass it one of the Environment.SpecialFolder values, and in return you get the path to that directory. There's a LOT of them, but really you'll use a few of them very frequently:
- Application Data is a place for you to create a folder for your application and store the things you used to want to write into Program Files. If the user doesn't need t know about or edit the file, put it here. Usually this is configuration files.
- MyDocuments is a folder you should use as a default for files your user edits, but only save there if they pick it. It's a good place to guess, but I've got 20+ folders I can't delete in mine because some program has hard-coded this as the only place they can save/load. Don't be a clown like their programmers.
- LocalApplicationData is a lot like ApplicationData, the difference is subtle. If you're on a Windows domain, this folder doesn't "roam". If you don't know what that means, it probably doesn't matter.
- CommonApplicationData is what you use if you want a machine with many users to use the same files for all users. It's like the other ApplicationData folders, but every user on the machine gets this one.
That's it. There's rarely good reasons to save to any of the other values unless the user specifically asks you. If you always use this method to get the ApplicationData folder, you'll always be saving to a place Microsoft supports. And you'll look a lot smarter than a lot of Very Big Companies.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Oct 13th, 2015, 04:34 PM
#13
Thread Starter
Hyperactive Member
Re: Cheking if a file exists
OK then . But how do I create a folder for my own in Application Data ?
I guess using something like this ?
Code:
Dim AAApath As String = System.Environment.SpecialFolder.ApplicationData
System.IO.Directory.CreateDirectory(AAApath & "AAA")
Because I am sure I am doing something wrong ...
-
Oct 13th, 2015, 05:25 PM
#14
Re: Cheking if a file exists
You're sure you're doing something wrong but not sure enough to bother reading the documentation for Environment.SpecialFolder? It's an enumeration, so each field is basically a number. It's only use is as an argument to the Environment.GetFolderPath method, which any example would have demonstrated. As the name suggests, the GetFolderPath method gets the path of a folder and the SpecialFolder value you pass tells it which folder to get the path of.
Having said all that, you can also use the My.Computer.FileSystem.SpecialDirectories object to get an application-specific folder path and automatically create that folder in the process.
-
Oct 14th, 2015, 01:36 AM
#15
Thread Starter
Hyperactive Member
Re: Cheking if a file exists
No , in fact I am more than sure that I bothered looking in the documentation . In fact I did in both the local Help and in Microsoft's website . Back in the VB6 era the Help documentation used to be much more helpful and understanding . Later they present more data about what a function is rather than what it does and even less about how it does it . There are , of course , examples in those online documents , but usually they are for much more advanced users .
Additionaly , "playing" with the windows' special folders , is something which I don't do every day and certainly haven't done up to now . Therefore there is an understandable fear that , during experiments , I might do something wrong !
The FileSystem.SpecialDirectories object is something I have already used and asked no question about because , although the Help files were once again awful , I did had at least fine examples in the VB .NET migration documents , which thankfully they took good care to be quite explanatory .
All in all , I don't frequent asking questions when there are ways around for me to find the answers on my own . Afterall , it takes much less time to try find something myself than expecting others to answer it to me . I only ask when I have already done my own search .
That being said , I guess now I'll have to find a computer on which I don't care much if something goes wrong and try my experiments there ... Maybe I should go in the Pacific . There have been many dreadful experiments that took place there , so that one more might not make a difference !
-
Oct 15th, 2015, 07:46 AM
#16
Re: Cheking if a file exists
A lot of people think "RTFM" is nice. It isn't, and it hasn't ever been, and it'll be great when developers can put on their big boy pants and stop using it. It's good that you snapped back. They need to get used to it and learn it's a lot faster to say, "Looks good to me!" or "Hmm... maybe not" than it is to spend a paragraph rewriting the documentation. Here's something nicer.
I can't tell you from memory if that code's right for a silly reason: I can't remember if Environment.GetSpecialFolder() puts a "\" at the end of the path or not. If it does, then that code's right. If not, then you have to add the "\". That's kind of annoying, so there's actually a class/method that handles that for you.
System.IO.Path.Combine() works out where the "\" needs to go, and makes sure you have it. Something like this is what I use to make my app folder:
Code:
Dim folderName As String = "MyFolder"
Dim baseDir As String = Environment.GetSpecialFolder(Environment.SpecialFolder.ApplicationData)
Dim folderPath as String = Io.Path.Combine(baseDir, folderName)
Debug.WriteLine(folderPath)
Io.Directory.CreateDirectory(folderPath)
The WriteLine is there in case I screw something up. I can always go delete the folder. Don't always worry about mucking with the filesystem, creating directories isn't ever going to break anything. The worst it does is make a mess.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Oct 15th, 2015, 09:51 AM
#17
Re: Cheking if a file exists
Originally Posted by iliekater
No , in fact I am more than sure that I bothered looking in the documentation . In fact I did in both the local Help and in Microsoft's website . Back in the VB6 era the Help documentation used to be much more helpful and understanding . Later they present more data about what a function is rather than what it does and even less about how it does it . There are , of course , examples in those online documents , but usually they are for much more advanced users .
Additionaly , "playing" with the windows' special folders , is something which I don't do every day and certainly haven't done up to now . Therefore there is an understandable fear that , during experiments , I might do something wrong !
The FileSystem.SpecialDirectories object is something I have already used and asked no question about because , although the Help files were once again awful , I did had at least fine examples in the VB .NET migration documents , which thankfully they took good care to be quite explanatory .
All in all , I don't frequent asking questions when there are ways around for me to find the answers on my own . Afterall , it takes much less time to try find something myself than expecting others to answer it to me . I only ask when I have already done my own search .
That being said , I guess now I'll have to find a computer on which I don't care much if something goes wrong and try my experiments there ... Maybe I should go in the Pacific . There have been many dreadful experiments that took place there , so that one more might not make a difference !
I'm not sure what .Net documentation you're checking, but the MSDN documentation for .Net, c#, Sql Server (T-Sql), & vb.net is far better than anything I've ever seen for vb6 or older. They explain what the function/class/namespace you're looking up is for, how to use it, what exceptions could be thrown, & there's a c# and vb.net (t-sql for sql server) example of how to use it.
If vb6's documentation had a quarter of that I probably wouldn't have switched to .Net as fast as I did back in 2003.
-
Oct 15th, 2015, 10:15 AM
#18
Re: Cheking if a file exists
I think what's going on here is something that happens with a lot of people, and it grates on a lot of nerd nerves. Let's roleplay.
I'm at a friend's house, we're watching TV and messing about on laptops. A TV show comes on and my friend says, "Whoa, what else was that guy in?" Here's how that scene can go:
- We frown, and spend 20 minutes talking about movies we've seen and trying to remember if the actor was in it, but neither of us really remember his name. Eventually, we give up and play Mario Kart.
- I go to imdb and look up the show, finding the actor's page from the credits. We spend a few minutes realizing he wasn't actually in anything we've seen, and wonder who the heck he looks like that we're confusing him with.
- I ROLL MY EYES and point to the laptop. "MAYBE YOU SHOULD ASK THE INTERNET," I triumphantly state.
Two of these things are what people with friends do. Oddly enough, the people that do one of them don't have many. The friend didn't ask the question because he was lazy, he asked it because he trusted me and thought I might know the answer. MS documentation's great, but sometimes doesn't tell you the BEST way to do something. For example, the current Environment.GetFolderPath() documentation doesn't even mention System.IO.Path. Not at all. In fact, this is its VB code example:
Code:
Dim companies =
{"Consolidated Messenger", "Alpine Ski House", "Southridge Video", "City Power & Light",
"Coho Winery", "Wide World Importers", "Graphic Design Institute", "Adventure Works",
"Humongous Insurance", "Woodgrove Bank", "Margie's Travel", "Northwind Traders",
"Blue Yonder Airlines", "Trey Research", "The Phone Company",
"Wingtip Toys", "Lucerne Publishing", "Fourth Coffee"}
' The IQueryable data to query.
Dim queryableData As IQueryable(Of String) = companies.AsQueryable()
' Compose the expression tree that represents the parameter to the predicate.
Dim pe As ParameterExpression = Expression.Parameter(GetType(String), "company")
' ***** Where(Function(company) company.ToLower() = "coho winery" OrElse company.Length > 16) *****
' Create an expression tree that represents the expression: company.ToLower() = "coho winery".
Dim left As Expression = Expression.Call(pe, GetType(String).GetMethod("ToLower", System.Type.EmptyTypes))
Dim right As Expression = Expression.Constant("coho winery")
Dim e1 As Expression = Expression.Equal(left, right)
' Create an expression tree that represents the expression: company.Length > 16.
left = Expression.Property(pe, GetType(String).GetProperty("Length"))
right = Expression.Constant(16, GetType(Integer))
Dim e2 As Expression = Expression.GreaterThan(left, right)
' Combine the expressions to create an expression tree that represents the
' expression: company.ToLower() = "coho winery" OrElse company.Length > 16).
Dim predicateBody As Expression = Expression.OrElse(e1, e2)
' Create an expression tree that represents the expression:
' queryableData.Where(Function(company) company.ToLower() = "coho winery" OrElse company.Length > 16)
Dim whereCallExpression As MethodCallExpression = Expression.Call(
GetType(Queryable),
"Where",
New Type() {queryableData.ElementType},
queryableData.Expression,
Expression.Lambda(Of Func(Of String, Boolean))(predicateBody, New ParameterExpression() {pe}))
' ***** End Where *****
' ***** OrderBy(Function(company) company) *****
' Create an expression tree that represents the expression:
' whereCallExpression.OrderBy(Function(company) company)
Dim orderByCallExpression As MethodCallExpression = Expression.Call(
GetType(Queryable),
"OrderBy",
New Type() {queryableData.ElementType, queryableData.ElementType},
whereCallExpression,
Expression.Lambda(Of Func(Of String, String))(pe, New ParameterExpression() {pe}))
' ***** End OrderBy *****
' Create an executable query from the expression tree.
Dim results As IQueryable(Of String) = queryableData.Provider.CreateQuery(Of String)(orderByCallExpression)
' Enumerate the results.
For Each company As String In results
Console.WriteLine(company)
Next
I... er... learned... something... from that? It doesn't even use the method. Sometimes MSDN whiffs. I bet none of the people praising the docs even bothered to go see if this documentation was good.
This forum works better when people help people. It works a lot less when we post to try and make ourselves feel smart. People come here because they already think we're smart. Let's demonstrate it by answering their questions, not bragging that we were able to find it ourselves.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Oct 15th, 2015, 11:19 AM
#19
Re: Cheking if a file exists
Originally Posted by Sitten Spynne
I think what's going on here is something that happens with a lot of people, and it grates on a lot of nerd nerves. Let's roleplay.
I'm at a friend's house, we're watching TV and messing about on laptops. A TV show comes on and my friend says, "Whoa, what else was that guy in?" Here's how that scene can go:
- We frown, and spend 20 minutes talking about movies we've seen and trying to remember if the actor was in it, but neither of us really remember his name. Eventually, we give up and play Mario Kart.
- I go to imdb and look up the show, finding the actor's page from the credits. We spend a few minutes realizing he wasn't actually in anything we've seen, and wonder who the heck he looks like that we're confusing him with.
- I ROLL MY EYES and point to the laptop. "MAYBE YOU SHOULD ASK THE INTERNET," I triumphantly state.
Two of these things are what people with friends do. Oddly enough, the people that do one of them don't have many. The friend didn't ask the question because he was lazy, he asked it because he trusted me and thought I might know the answer. MS documentation's great, but sometimes doesn't tell you the BEST way to do something. For example, the current Environment.GetFolderPath() documentation doesn't even mention System.IO.Path. Not at all. In fact, this is its VB code example:
Code:
Dim companies =
{"Consolidated Messenger", "Alpine Ski House", "Southridge Video", "City Power & Light",
"Coho Winery", "Wide World Importers", "Graphic Design Institute", "Adventure Works",
"Humongous Insurance", "Woodgrove Bank", "Margie's Travel", "Northwind Traders",
"Blue Yonder Airlines", "Trey Research", "The Phone Company",
"Wingtip Toys", "Lucerne Publishing", "Fourth Coffee"}
' The IQueryable data to query.
Dim queryableData As IQueryable(Of String) = companies.AsQueryable()
' Compose the expression tree that represents the parameter to the predicate.
Dim pe As ParameterExpression = Expression.Parameter(GetType(String), "company")
' ***** Where(Function(company) company.ToLower() = "coho winery" OrElse company.Length > 16) *****
' Create an expression tree that represents the expression: company.ToLower() = "coho winery".
Dim left As Expression = Expression.Call(pe, GetType(String).GetMethod("ToLower", System.Type.EmptyTypes))
Dim right As Expression = Expression.Constant("coho winery")
Dim e1 As Expression = Expression.Equal(left, right)
' Create an expression tree that represents the expression: company.Length > 16.
left = Expression.Property(pe, GetType(String).GetProperty("Length"))
right = Expression.Constant(16, GetType(Integer))
Dim e2 As Expression = Expression.GreaterThan(left, right)
' Combine the expressions to create an expression tree that represents the
' expression: company.ToLower() = "coho winery" OrElse company.Length > 16).
Dim predicateBody As Expression = Expression.OrElse(e1, e2)
' Create an expression tree that represents the expression:
' queryableData.Where(Function(company) company.ToLower() = "coho winery" OrElse company.Length > 16)
Dim whereCallExpression As MethodCallExpression = Expression.Call(
GetType(Queryable),
"Where",
New Type() {queryableData.ElementType},
queryableData.Expression,
Expression.Lambda(Of Func(Of String, Boolean))(predicateBody, New ParameterExpression() {pe}))
' ***** End Where *****
' ***** OrderBy(Function(company) company) *****
' Create an expression tree that represents the expression:
' whereCallExpression.OrderBy(Function(company) company)
Dim orderByCallExpression As MethodCallExpression = Expression.Call(
GetType(Queryable),
"OrderBy",
New Type() {queryableData.ElementType, queryableData.ElementType},
whereCallExpression,
Expression.Lambda(Of Func(Of String, String))(pe, New ParameterExpression() {pe}))
' ***** End OrderBy *****
' Create an executable query from the expression tree.
Dim results As IQueryable(Of String) = queryableData.Provider.CreateQuery(Of String)(orderByCallExpression)
' Enumerate the results.
For Each company As String In results
Console.WriteLine(company)
Next
I... er... learned... something... from that? It doesn't even use the method. Sometimes MSDN whiffs. I bet none of the people praising the docs even bothered to go see if this documentation was good.
This forum works better when people help people. It works a lot less when we post to try and make ourselves feel smart. People come here because they already think we're smart. Let's demonstrate it by answering their questions, not bragging that we were able to find it ourselves.
Huh, what documentation are you looking at?
Here's the documentation's code example for Environment.GetFolderPath():
Originally Posted by MSDN
vb Code:
' Sample for the Environment.GetFolderPath method
Imports System
Class Sample
Public Shared Sub Main()
Console.WriteLine()
Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.System))
End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'GetFolderPath: C:\WINNT\System32
'
Was the first thing in my google search "msdn Environment.GetFolderPath"
Environment.GetFolderPath Method (Environment.SpecialFolder) (System)
There's also the SpecialFolders enum documentation too: Environment.SpecialFolder Enumeration (System)
-
Oct 15th, 2015, 11:37 AM
#20
Re: Cheking if a file exists
No lie, when I do the same Google search I end up on this page and get that example. You're tuned to .NET 4.0's version, which is correct. It seems like they've borked the 4.5 and 4.6 documentation.
Which is why I try to answer questions even if it seems like the documentation should be clear, and if I intend to lean on it I go visit it first and link to what I saw.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Oct 15th, 2015, 06:20 PM
#21
Re: Cheking if a file exists
Originally Posted by Sitten Spynne
A lot of people think "RTFM" is nice.
Who said I'm trying to be nice? I'm not here to be nice. If people get upset because I'm not nice to them then maybe they need to put their big boy pants and stop being so fragile. If you're too lazy to RTFM then you deserve what you get as far as I'm concerned. If you have RTFMed and done what you can and still need help then I'm here at your disposal. You can keep coddling people all you want.
-
Dec 8th, 2015, 11:52 AM
#22
Thread Starter
Hyperactive Member
Re: Cheking if a file exists
What's an RTFM ?
I get something in Wikipedia about a manual . But I think (and hope) I am wrong .
-
Dec 8th, 2015, 12:44 PM
#23
Re: Cheking if a file exists
"Read The <expletive> Manual". It's an aggressive way to tell someone you think their question is stupid, and that the answer is obvious if they read the documentation. It isn't helpful and there's kinder ways to say the same thing.
I don't like it because reading the documentation can be a skill one picks up over time, and occasionally there's issues in the documentation that make it unusable. And sometimes the documentation's a lot more complex than it needs to be. And sometimes a one-paragraph summary works better than the four pages of documentation plus examples. I come here to have fun answering questions, and my style of RTFM is I don't reply to the thread if I think the OP isn't putting forth a lot of effort.
Looking back, I think I interpreted JMC's answer as far more aggressive than it actually was, probably because you got flustered about it. Maybe I was feeling kind of grouchy that day. It didn't help that MSDN was having some kind of bug and displaying the wrong examples for me.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Dec 8th, 2015, 01:15 PM
#24
Re: Cheking if a file exists
Originally Posted by iliekater
What's an RTFM ?
I get something in Wikipedia about a manual . But I think (and hope) I am wrong .
It's short for "Read the F***ing Manual"
-
Dec 8th, 2015, 05:56 PM
#25
Re: Cheking if a file exists
Originally Posted by iliekater
What's an RTFM ?
I get something in Wikipedia about a manual . But I think (and hope) I am wrong .
It isn't originally a programming term and comes from the fact that people would get appliances like a VCR and then ask other people to spend their time explaining how to operate it when there was a perfectly good manual that explained exactly that in the box.
The thing is, many people think that if they do RTFM then they are going to end up spending time reading information that they don't actually need and they figure that if they get someone else to explain it to them then they will only get the information that they actually need. It doesn't really bother them that they're basically saying that their own time is more valuable than the other person's or that some of that extra information may actually come in handy later on. They just figure they can ask someone else again when that information is needed.
With regards to programming in particular, I lost count a long time ago of the number of times I've found information that is useful for another topic while looking for a solution to a specific problem. I've also lost count of the number of times that I've been able to answer someone else's question on a subject that I have no experience with, simply by reading the documentation that they had just as much access to as me. That's not just a recent thing either. I answered numerous questions about the DataGrid control, which I've pretty much never used myself, back when I first joined this forum, ten years ago.
As far as I'm concerned, what it comes down to is that you have a responsibility to do what you can for yourself before you ask others for help. Particularly if you have an issue with a specific type or member, if you are asking questions without having read the documentation then you're being lazy. If you have read the documentation and searched the web and you either can't find what you need or you can't understand what you find. Only then should you be asking questions on forums like this.
Of course, I'm not the king of programming forums so that's not a rule that I can enforce, but I make no apologies for having string opinions on the matter. I do and have spent many hours helping people who do help themselves and even those who haven't in some cases. I'm here to help people become better developers and I think that encouraging them to not use the tools at their disposal is counterproductive in that regard.
-
Dec 8th, 2015, 06:00 PM
#26
Re: Cheking if a file exists
Originally Posted by Sitten Spynne
...my style of RTFM is I don't reply to the thread if I think the OP isn't putting forth a lot of effort.
But does that actually help people? That is certainly one approach but then you end up with people like the one you will have seen in another thread recently complaining that they never get answers to their questions. I've seen numerous people like that over the years and their questions being ignored doesn't make them more likely to use the Help menu. My thinking is that, the next time they come to ask a question, if they recall my blunt comments about their level of effort last time, they may just decide to increase that effort, either through shame or otherwise. That is actually making them a better developer and I'm quite happy to be thought a villain to achieve that end.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|