The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: oex on February 28, 2010, 02:52:51 AM

Title: exist
Post by: oex on February 28, 2010, 02:52:51 AM
Is there an 'exist' function for directories? exist c:\dirpath without trailing backslash works but beeps :lol
Title: Re: exist
Post by: Gunner on February 28, 2010, 03:01:52 AM
    invoke  SHGetFileInfo, addr MyDir,
                            NULL,
                            addr sfi,
                            sizeof sfi,
                            SHGFI_DISPLAYNAME


Seems to work for directories, not sure if it is the best way...  returns 0 if the directory does not exist and 1 if it does
Title: Re: exist
Post by: hutch-- on February 28, 2010, 03:06:39 AM
I know this is crude but I store the current path and change directory to a path to test. If it returns an error it does not exist. If it does not return an error I change back to the current path with a verified directory.
Title: Re: exist
Post by: sinsi on February 28, 2010, 03:12:30 AM
Use GetFileAttributes and test the return value for INVALID_FILE_ATTRIBUTES (error) then FILE_ATTRIBUTE_DIRECTORY.
Title: Re: exist
Post by: dedndave on February 28, 2010, 03:14:12 AM
FindFirstFile ?
Title: Re: exist
Post by: sinsi on February 28, 2010, 03:18:32 AM
GetFileAttributes takes 1 parameter (the name) and returns a dword, no need to allocate structures then close handles.
Title: Re: exist
Post by: oex on February 28, 2010, 03:20:11 AM
:lol the only one I'd thought of was FindFirstFile.... let me rephrase which one's best

EDIT: Thanks Sinsi (and all :wink)will try that one then :bg
Title: Re: exist
Post by: Gunner on February 28, 2010, 03:22:06 AM
There are many ways to kill a bird  :bg  Didn't think about FindFirstFile.
Title: Re: exist
Post by: oex on February 28, 2010, 03:22:50 AM
You can kill a bird with FindFirstFile? :lol
Title: Re: exist
Post by: BlackVortex on February 28, 2010, 08:55:56 AM
SHGetFileInfo is brutally slow and too much for this simple task. I'd go with Sinsi's suggestion. Searching also found this thread :
http://www.masm32.com/board/index.php?topic=5259.0