Weird issue...

SphinCorp

Member
Joined
Jun 8, 2008
Messages
5
Programming Experience
1-3
Ok... So I need to be able to open a file with my app and perform an action based on this. Someone told me to use System.Environment.GetEnvironmentVariables()
but that doesn't work too well... Could someone post some example code or something?
 
Do you mean to retrieve the command line argument that contains the path to the file to open? If so, here's how to retrieve them :

VB.NET:
Environment.GetCommandLineArgs()

Otherwise, if you want to access files in the same directory as your exe file, here it is :

VB.NET:
AppDomain.CurrentDomain.BaseDirectory

By the way, do not use "Application.ExecutablePath" because it does not return international characters well...

If you are looking to use common directories use this technique :

VB.NET:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

I hope one of those actually answered your question and I didn't write all this for nothing :p
 
Yay!(sort of...)

Ok... It works, but it can;t use spaces in the directory name... HELP?!?!?!

VB.NET:
dim COM as string
dim com_arg as string
dim called as boolean

Try
            com_arg = Environment.GetCommandLineArgs.GetValue(1)
            If My.Computer.FileSystem.FileExists(com_arg) = True Then
                com_arg = Environment.GetCommandLineArgs.GetValue(1)
                COM = "call" & com_arg
                called = True
            End If

        Catch

        End Try
 
Ahh.. this younger generation of programmers that know nothing of DOS

How do you separate command from argument in dos? Use spaces. How do you separate arguments from each other in DOS? Use spaces


So if you pass a filename with spaces, DOS will parse them as SEPARATE arguments. (DOS; nothing to do with your app, your app hasnt even been launched a tthis time)

Use quotes (and read up on DOS)

dir c:\program files
>Cannot find "C:\program"
>Cannot find "files"

dir "c:\program files"
>Directory listing for....
 
Back
Top