Variable path names

Blitz3D Forums/Blitz3D Beginners Area/Variable path names

I had searched through the file path examples and have not been able to resolve a coding problem. I have used the following code to try and read a file path from an .ini file.

String manipulation resolved my no file found problem.

Removed original code, updated code below. The reason my variable path was not being recognised was it was constructed :-

"data1.dat"

I have included the code I 'hacked' together to strip of the speechmarks from the pathname. Hope this is useful to somebody.....

When I hard coded the path, it worked fine. But when I attempted to use the 'variable' I had read in from a .txt file, the file could not be found.

Code looks fine.
You didn't supply us with enough information.
You didn't show us the returned value from the ReadString$ command. I suspect that you intended to use the ReadLine$ command, not the ReadString$ command.

Your suggestion has got me thinking though.... thanks.

I modified my code so that the Readline$ is used again and pasted some text on the end to make sure
no 'hidden' chars, it still initially failed to recognise my variable path ? transferred the string into an array, stripped of the speechmarks, hey presto!



;  Note to run run this piece of code
;  It will be necessary to have a text
;  file saved at:-
;  "C:\Blitzer\DataPath"
;  with the following text on the first line
;  "C:\Blitzer\data1.dat""
.main

AppTitle "Stripping off the speech marks from a pathname"
Graphics 640, 420, 16, 2 ; 


Dim path$(50);chars max need this for string manipulation
			 ; to strip off the " marks

filein = ReadFile("C:\Blitzer\DataPath")

;Readin the path from the file:-

Data1path$ = ReadLine$( filein)

;close the file which holds the path to the first piece of data:-

CloseFile( filein );

Print "Debug.. the path For Data1path$ is:-"
Print Data1path$ +":End of path"      ;   displaying the fact the
									  ;   path from the .ini file
									  ;   is prefixed and suffixed
									  ;   by :   "{pathname}"

; ---stripping off speech marks--------
Print "Stripping off speech marks from start and end of path:-"

Data2path$ = Data1path$
endofstring = Len (Data1path$)-1
For T = 2 To endofstring
x=T-2
path$(x)=Mid$(Data2path$,t,1)

Print Mid$(Data2path$,t,1)
newpath$=newpath$+Mid$(Data2path$,t,1)
Next

;Print newpath$
;For T = 1 To Len(newpath$)
;Print Mid$(name$,t,1)
;Next
filename$=newpath$


Print "filename$ is now set as:-----"+filename$
If FileType(filename$)=1 Then Print "The file exists!"
If FileType(filename$)=0 Then Print "File not found!"
If FileType(filename$)=2 Then Print "This is a directory!"

filename$= "C:\Blitzer\data1.dat"
Print filename$
If FileType(filename$)=1 Then Print "The file exists!"
If FileType(filename$)=0 Then Print "File not found!"
If FileType(filename$)=2 Then Print "This is a directory!"
If filename$=Data1path$ Then Print "One file equals the other...."

Print "Press any key to quit."

WaitKey()




When I hard coded the path, it worked fine. But when I attempted to use the 'variable' I had read in from a .txt file, the file could not be found. Incidentally the 'variable' path printed to the screen had looked exactly the same as the hard coded path, however the " " at the start and end of the path prevented the file from being recognised.

Thanks to RWolbeck for his input.

By default, Blitz looks for info to be loaded in the same directory/folder as where the Blitz program was loaded and run. You may want to create subdirectories (ie folders) inside the one where the program resides.
So, in your case:

Blitzer ;your directory
DataPath ;within the Blitzer directory, new directory called DataPath
Saves ;for game saves
Maps ;for, whatelse? maps!
etc...

When you want to access data1.dat inside DataPath, you would use:
filein = ReadFile("DataPath\data1.dat")

Blitz will start from wherever on your hard drive the directory "Blitzer" is found, and see if it can find the subdirectory DataPath, and looking inside it, find the file data1.dat.

This way, you can always move "Blitzer" around in your hard drive's many folders, and it won't matter where it is, it will always find the data.

Thanks Sir Gak, my file manipulation knowledge has moved yet further forward.. Thanks again. I had been using a file manipulation GUI I hacked togehter in VB6 to modify my pathname files, this was the cause of the unwanted {""} at the start and end of my pathnames.

My data display project has reached the awkward phase where I've to stop tinkering with the GUI that displays the data (written in Blitz3D....) and put my efforts into the Hardware which will produce the data for representation on a cartesian graph.