Correct filepath?
Correct filepath?
How do I get a correct filepath?
"test.txt" and "c:/program files\tEst.txt" both become "C:\Program Files\test.txt".
"test.txt" and "c:/program files\tEst.txt" both become "C:\Program Files\test.txt".
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
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!

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!

BERESHEIT
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!
Look at this nice screenshot:

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.
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.
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
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.
-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
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
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
Here is the MS page:
http://msdn.microsoft.com/library/defau ... thname.asp
something like this :
API's are basically calls to functions in dll files.
Code: Select all
If OpenLibrary(1,"kernel32.dll")
CallFunction(1,"GetLongPathName",ShortPath.s, LongPath.s, buffer)
EndIfHere 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"))
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"))
Everyone can be wrong. It is NOT possible to do it by using the FileSystem lib.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.
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


