Correct filepath?

Everything else that doesn't fall into one of the other PB categories.
halo
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jan 26, 2004 2:49 am

Correct filepath?

Post by halo »

How do I get a correct filepath?

"test.txt" and "c:/program files\tEst.txt" both become "C:\Program Files\test.txt".
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

There is lots to discover in the manual. Look under "FileSystem" at the commands available there, ex. Examinedirectory, Usedirectory, etc. Also you can do parsing of your own using GetPathPart, GetFilePart, and GetExtensionPart. Don't worry about case too much as the OS will find a file regardless of the case you use to search for it.

P.S There is a little icon some members insert at times like this. I'll restrain myself.

Who am I kidding? No I won't!

Image
BERESHEIT
Jellybean
User
User
Posts: 95
Joined: Wed Aug 24, 2005 7:33 pm

Post by Jellybean »

netmaestro wrote:There is lots to discover in the manual. Look under "FileSystem" at the commands available there, ex. Examinedirectory, Usedirectory, etc. Also you can do parsing of your own using GetPathPart, GetFilePart, and GetExtensionPart. Don't worry about case too much as the OS will find a file regardless of the case you use to search for it.

P.S There is a little icon some members insert at times like this. I'll restrain myself.

Who am I kidding? No I won't!

Image
ImageNo no no!
ImageBefore you gun down others...
ImageRTFQ!
ImageBeing angry at...
ImagePeople who ask proper questions...
ImageMakes me wonder
:?: whether you'll...
Imageget old or not. (Mafia threat)

ImageLet me explain it to you...

Look at this nice screenshot:
Image
See where it says "C:\PHP\chart-0.7\chart.php"? Let's suppose that the user browsed, in an open file requester, to "C:\PHP" and then typed in "CHArt-0.7\chaRT.PHP". The point is, that the status bar text should still be "C:\PHP\chart-0.7\chart.php".

Please, explain where in the manual a function that does the requested, can be found.

Image


Ok, it IS possible to do it "manually" by using the functions you described, but that's a bit like point people to the 2D Drawing lib when they want to create button. Sure, you could draw a button using pixels, but there are better ways.
halo
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jan 26, 2004 2:49 am

Post by halo »

Yes, my question is still unanswered. I want the correct unique filename, what windows converts my messy filename to before loading a file.

The API command GetFullPath() gets the current directory, which is not what I want.

So I should say to you, RTFQ, DA.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I gave you some help. I told you where to look in the manual. So calling me names is not warranted. I didn't have to do that. If you don't want people to suggest the manual it would be a good idea to let us know up front that "I've tried this, I've looked through that, but I'm unable to figure out how to... " can anyone suggest something else? Too many users are too lazy to do any research on their own and when they want to know how to do something the first place they go is the forum. Best to clue us in that you're not doing that.

-AND-

Post your coding questions in the coding questions forum

-AND-

I can solve your problem now but you will apologize for calling me a dumbass before I'll give you any more help on any topic.
BERESHEIT
halo
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jan 26, 2004 2:49 am

Post by halo »

Don't dish it out if you can't take it, especially if you're wrong. The file system commands don't even have anything to do with my question.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I didn't dish it out. I don't object to the RTFQ , it's the DA part that is unwarranted and probably illegal on this (and most) forums. (-stops watching topic-)
BERESHEIT
halo
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jan 26, 2004 2:49 am

Post by halo »

Using BlitzPlus, I was able to get it with the WinAPI command GetLongPathName (kernel32). This command is not in PureBasic's API libs. How can I add it?

Here is the MS page:
http://msdn.microsoft.com/library/defau ... thname.asp
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

something like this :

Code: Select all

If OpenLibrary(1,"kernel32.dll")
CallFunction(1,"GetLongPathName",ShortPath.s, LongPath.s, buffer)
EndIf
API's are basically calls to functions in dll files.
halo
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jan 26, 2004 2:49 am

Post by halo »

Here it is. Write this one down somewhere:

Global *POINTER_GetLongPathName

lib=OpenLibrary(#PB_ANY,"kernel32.dll")
*POINTER_GetLongPathName=IsFunction(lib,"GetLongPathNameA")

Procedure GetLongPathName_(file$,temp,size)
ProcedureReturn CallFunctionFast(*POINTER_GetLongPathName,file$,temp,size)
EndProcedure

Procedure.s NiceFileName(file$)
file$=UCase(file$)
file$=ReplaceString(file$,"/","\")
If FindString(file$,".",1)=0
If Right(file$,1)<>"\"
file$=file$+"\"
EndIf
EndIf
size=Len(file$)+1
temp=AllocateMemory(size)
GetShortPathName_(file$,temp,size)
file$=PeekS(temp)
GetLongPathName_(file$,temp,size)
file$=PeekS(temp)
FreeMemory(temp)
ProcedureReturn file$
EndProcedure

MessageRequester("",NiceFileName("c:/wInDoWs\eXpLoReR.eXe"))
Jellybean
User
User
Posts: 95
Joined: Wed Aug 24, 2005 7:33 pm

Post by Jellybean »

Jellybean wrote:Ok, it IS possible to do it "manually" by using the functions you described, but that's a bit like point people to the 2D Drawing lib when they want to create button. Sure, you could draw a button using pixels, but there are better ways.
Everyone can be wrong. It is NOT possible to do it by using the FileSystem lib.

CopyDirectory() returns a long, so clearly not the correct filepath.
CopyFile() returns a long, so clearly not the correct filepath.
CreateDirectory() returns a long, so clearly not the correct filepath.
DeleteDirectory() returns a long, so clearly not the correct filepath.
DeleteFile() returns a long, so clearly not the correct filepath.
DirectoryEntryAttributes() returns a long, so clearly not the correct filepath.
ExamineDirectory() returns a long, so clearly not the correct filepath.
NextDirectoryEntry() after ExamineDirectory() returns a long, so clearly not the correct filepath.
DirectoryEntryName() after NextDirectoryEntry() after ExamineDirectory() returns a string, but, as the description says, it returns the filename. Not including the path.
DirectoryEntrySize() returns a long, so clearly not the correct filepath.
FileSize() returns a long, so clearly not the correct filepath.
IsDirectory() returns a long, so clearly not the correct filepath.
IsFilename() returns a long, so clearly not the correct filepath.
RenameFile() returns a long, so clearly not the correct filepath.
UseDirectory() is an internal PB command and doesn't return anything at all.

None of the commands in the file library can be used for this, either.

So please, netmaestro, can you tell me how you would do this?
Brice Manuel

Post by Brice Manuel »

Jellybean wrote: Imageget old or not. (Mafia threat)
Finally, a smiley that looks like me :wink:
Post Reply