CommandLine() bad for opening files...

Blitz3D Forums/Blitz3D Programming/CommandLine() bad for opening files...

bytecode77(Posted 2008) [#1]
hi!

file$ = CommandLine()
file$ = Replace(file$, Chr(34), "")
file$ = Trim(file$)

when i try to open a file to the path of file$, i always get a MAV.

the commandline includes the whole path including the drive D:\ and the filename. i replaced the "" and trimmed it. thats all i can do and it still doesnt work.
important is, that CurrentDir() = "C:\Documents and settings\......." when i add a commandline. when i don't, the currentdir is usualy the dir of the executable...

what am i doing wrong here?
thx for upcomming answers:)


jfk EO-11110(Posted 2008) [#2]
1. What, you say CurrentDir gives you a diffrent value depending on if you used CommandLine before or not?

2. How do you use Commandline, an external app is calling your exe with an argument, or you drop a file onto the exes icon in the explorer, or you used the IDE's command line option?

3. Did you already a Print commandline$(): waitkey() ? Just to see what's going on.

Note: when you dragndrop an icon onto your exes icon, the path will be given in its old msdos form, 8.3 thingie, like joe~27.htm


bytecode77(Posted 2008) [#3]
1. yes.
2. i'm dropping a file into the blitz executable (i dont mean the bb compiler!)
3. nope, just calling it once EDIT::::: ah you mean to debug? of course!
note. nope, it seems like it uses the windoes unlimited.unlimited format

so where's the mistake?


bytecode77(Posted 2008) [#4]
hm. this is not the first time i'm having this problem and i bet most of you had this problem, too. so "if there's a problem, there must be a solution". thats at least what someone's signature sais, whose name i cant remember... ;)


jfk EO-11110(Posted 2008) [#5]
Well, I only remember this one:
The computer is the solution, what we need now is the problem.

Ehrm, anyhow, not very useful here.

Did you try this:

file$=commandline$()
print filetype(file$)
waitkey()


GfK(Posted 2008) [#6]
You're sure you're using absolute paths? Also, don't you need the quotation marks around it if the path/filename contains spaces?

Also, you're not trying to open a read-only file with OpenFile(), are you? Because that will never ever work. Use ReadFile().


jfk EO-11110(Posted 2008) [#7]
I just tried this:

file$= CommandLine$()
file$=Replace$(file$,Chr$(34),"")
Print file$
Print FileType(file$)
WaitKey()
End


And it works, FIletype returns 1. I tried it with a bak file that was in the same folder as the exe, on C:. And you're right, the path is a long filenames path. THe msdos thing happens only on fat32 systems.

Probably you shouldn't use Trim?


bytecode77(Posted 2008) [#8]
well, it says filetype=1 and prints the alsolute path and filename on the screen, but i still get a MAV propably on the readfile command.


bytecode77(Posted 2008) [#9]
nah wait! the problem now doesnt seem to lie in the readfile() function, but in another writefile function.
i'm reading the file, the user drops on the exe and i'm writing an output file! the output file is not properly created at all!

thats because the currentdir() is something like
c:\documents and something\blah\
i had to write a function that filters the path of the commandline and thats my currentdir then. but is there a cleaner way?


bytecode77(Posted 2008) [#10]
hm, seems like there isnt
i will use my pathonly() function for this!

thanks for help :)


jfk EO-11110(Posted 2008) [#11]
I still don't understand what exactly the problem was :o). But if you have troubles with currentDir, then you may have to try this at the beginning of your program:

ChangeDir SystemProperty$("appdir")

This is also required in screensavers etc., basicly whenever windows is confused about where it is ^^


bytecode77(Posted 2008) [#12]
ah thats what i finaly was looking for!
thanks dude :)