News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Check path validity

Started by jdoe, September 07, 2006, 06:50:27 PM

Previous topic - Next topic

jdoe


Hi,

I've search many times a way to verify if a path is valid (exist or not) and never found something reliable.
My question is simple...

Does a win32 API can do this verification or is there a reliable method to do it ?

VALID = C:\WINDOWS
VALID = C:\MASM32\

NOT VALID = C:\WINDOWS/system32
NOT VALID = F\TEMP\\TEMP
NOT VALID = C:\*\Program Files\
NOT VALID = C:\TEST&\|P\
NOT VALID = D:\"temp"
NOT VALID = \C

I think you got the point

Thanks

P1

Good Luck here, file system error is after you try it, it's tells you.

Though, the rules are not too many, if you want to write one. 

Regards,  P1  :8)

anon

There are a lot of "Path" functions available in the Windows Shell API.
Do a search for PathFileExists in the PSDK. It might be what you are
looking for.

hutch--

jdoe,

I tend to use SetCurrentDirectory() for these types of tasks. Change to what you want to test and check the return value to see if it succeeded. You can store the original location if you need to rteturn to it later.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jdoe

Thanks for your replies,

One thing I forgot to say and include in my examples is that a path include files and directories but I know now why I never been able to find a solution because there is no easy way to do it.

Why should I need to do such validity checking you may ask. I'm working on functions like GetParentFolder or GetPathExtension and it's not impossible that giving a path that don't exist as a parameter of these kind of functions occur (before creating it for example or using the returned value on the file system). Another reason is to validate the parameter supplied to these functions to make sure the returned value is really a path.

Like P1 said, I should do one myself and I thought about it before but reading this http://windowssdk.msdn.microsoft.com/en-us/library/ms687127.aspx made me doubt the reliability of it.

jdoe

I had to write one, so I did. This topic now ends on a good note.

Giving up is not a solution   :lol


; Azimut Project
; Copyright (c) 2007-2008 Philippe Coulombe
; All rights reserved

.486
.MODEL FLAT,STDCALL
OPTION CASEMAP:NONE


.NOLIST
INCLUDE \AZIMUT\INCLUDE\AZIMUT.INC
INCLUDE \AZIMUT\INC32\kernel32.inc
INCLUDE \AZIMUT\INC32\shlwapi.inc
.LIST


.CODE

;
; Returns non-zero if the path is valid
;
; p_lpszPath = Pointer to the path to be validated
;
AzmtPathIsValidA PROC p_lpszPath:DWORD

    invoke PathIsDirectoryA, p_lpszPath
    test eax, eax
    jz @F

    ret

@@:
    invoke CreateFileA, p_lpszPath, 0, 0, NULL, CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, NULL
    cmp eax, INVALID_HANDLE_VALUE
    je @F

    invoke CloseHandle, eax

    ret

@@:
    invoke GetLastError
    cmp eax, ERROR_FILE_EXISTS
    jne @F

    ret

@@:
    xor eax, eax

    ret

AzmtPathIsValidA ENDP

END



Vortex

Philippe,

I see that you created your own master include file Azimut.inc Will you release it to public?

jdoe

Quote from: Vortex on January 07, 2008, 10:09:31 PM
Philippe,

I see that you created your own master include file Azimut.inc Will you release it to public?

Vortex,

My library had few functions that were incompletes and in the last few weeks I fought to have spare time to work on it and make it ready to use. It will be part of Azimut Project and will include import libraries and prototypes (completed for win32/win64). AZIMUT.INC will include all the constants (almost completed) and the structures (work in progress because I have few things to solve about win32/win64).

I'm planning a release without the structures and I thought I could do it before the end of 2007 but I was too busy with projects at my office. 24 hours in a day it's not enough !!!

It's a lot of work but I want to give this to the win32 assembly programmers.

Stay tuned   :wink


jdoe

Stupid me. After more tests, I realized that this function fails if intermediate folders do not exist.

A fix will come later. Sorry.

:(



Tedd

I don't think there's any nice way to do it - as far as function calls are concerned.
You can check whether a given path (drive, file, or folder) exists (that's easy), but to decide if some random string is a valid path becomes endlessly more complex. I wouldn't be surprised if there's some hidden function that takes care of it, but it's obviously undocumented and top secret ::)
To check a path you would need to handle 'normal' paths and relative paths, as well as UNC paths (for network drives), direct device paths, and any other weird methods.. Then, just when you think you've had enough, there are limits on the characters allowed in file/folder names, and the lengths of names, aanndd the number of sub-folders allowed in a path, and the maximum number of characters in a path - and all of these are different depending on the file-system of the drive that the path refers to :dazzled:
No snowflake in an avalanche feels responsible.