473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

File.Exists()

I'm trying to check whether a .lnk (LNK - Windows shortcut file)
exists. I can successfully create the lnk file and then go browse to
the folder and see the lnk file is there, but calling
File.Exists("test.lnk") fails. How can I do this?
Nov 16 '07 #1
5 3398
>I'm trying to check whether a .lnk (LNK - Windows shortcut file)
exists. I can successfully create the lnk file and then go browse to
the folder and see the lnk file is there, but calling
File.Exists("test.lnk") fails. How can I do this?
Have you tried specifying the fully qualified file path?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '07 #2
On Nov 16, 4:20 pm, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
I'm trying to check whether a .lnk (LNK - Windows shortcut file)
exists. I can successfully create the lnk file and then go browse to
the folder and see the lnk file is there, but calling
File.Exists("test.lnk") fails. How can I do this?

Have you tried specifying the fully qualified file path?

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.
yeah. I used Directory.SetCurrentDirectory() to set the path so I
wouldn't have to type in the full path. But not running that and just
inserting the full path still results in the same failure.
Nov 16 '07 #3
use Path.Combine to create a absolute path

--
Sheng Jiang
Microsoft MVP in VC++
<re***********@gmail.comwrote in message
news:87**********************************@c29g2000 hsa.googlegroups.com...
On Nov 16, 4:20 pm, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
I'm trying to check whether a .lnk (LNK - Windows shortcut file)
exists. I can successfully create the lnk file and then go browse to
the folder and see the lnk file is there, but calling
File.Exists("test.lnk") fails. How can I do this?

Have you tried specifying the fully qualified file path?

Mattias

--
Mattias Sjögren [C# MVP] mattias @
mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.
yeah. I used Directory.SetCurrentDirectory() to set the path so I
wouldn't have to type in the full path. But not running that and just
inserting the full path still results in the same failure.
Nov 16 '07 #4
That's not the problem. The problem is the File.Exists() returns
false no matter what if it is a .lnk file. I even created one in c:\
and called File.Exists("c:\\test.lnk") and it still returns false.
Nov 19 '07 #5
Ok, after much headache, my boss found that windows hides the file
extension for .lnk files no matter what. So File.Exists("c:\
\test.lnk.lnk") returns true.
Nov 19 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Geiregat Jonas | last post by:
is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); } a good way of checking if a file exists or not, if not how should I do it ?
3
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
18
by: Dan | last post by:
I have code like the following to test for existence of a file. I know the file is there, but File.Exists returns FALSE. The problem appears to be that the file is in a directory beneath "My...
2
by: Zeno Lee | last post by:
I'm using File.Exists to test a file on my C: drive. My program was strongly named and had caspol -af run on it to allow it to run from the network. There are 3 ways I am doing this: 1) Run...
2
by: Chris Fink | last post by:
I am using the System.IO.File class to determine if a file exists on a network share. The File.Exists method keeps returning false, even though the file does exist. The MSDN documentation...
4
by: DEWright_CA | last post by:
I am trying to see if a file exists in a virtual directory, and if so run a method. I try doing File.Exists and the method runs but the file isn't there. Is there a web version of File.Exists or...
52
by: paytam | last post by:
Hi all Can anyone tell me how can I check that a file exist or no.I mean when you use this commands FILE *fp; if(!fp) //Could not open the file doen't show why it can not open it,may be the...
17
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
12
by: snow | last post by:
Hi All, I noticed if file path has a white space, for example "C:\my document \test.txt", the function File.Exists(filePath) always return false in release mode. How could I make this function...
7
by: sprash | last post by:
Newbie question: I'm trying to determine if a file physically exists regardless of the permissions on it Using File.Exists() returns false if it physically exists but the process does not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.