| View previous topic :: View next topic |
| Author |
Message |
angerist Grandmaster Cheater Supreme
Reputation: 0
Joined: 18 Jun 2007 Posts: 1011 Location: Australia.
|
Posted: Sun Oct 05, 2008 12:57 am Post subject: Opening a file from same folder as your App |
|
|
Alright so I have no control over where the users choose to save my App so I cant use directory's. I know how to do this in C# but I really need to know how to do it in either Delphi or VB. Preferably Delphi.
Here's the code I created in C#
| Code: | string _sAppPathName = Process.GetCurrentProcess().MainModule.FileName;
string _sDataFilePath = _sAppPath.Substring(0, _sAppPath.Length - (_sAppPath.Length - _sAppPath.LastIndexOf(@"\"))) + @"\yourfilename.yourextension"; |
And on a different note I also need to find out how to replace files. So say if I had the files that I wanted to replace in the same folder as my app and I wanted them to go to a directory on the users computer with a press of a button. Any suggest and snippets would be appreciated
I need this in delphi. Looking forward to some answers
Thankyou,
Angerist.
_________________
Last edited by angerist on Mon Oct 06, 2008 2:05 am; edited 1 time in total |
|
| Back to top |
|
 |
NothingToShow Grandmaster Cheater Supreme
Reputation: 0
Joined: 11 Jul 2007 Posts: 1579
|
Posted: Sun Oct 05, 2008 1:03 am Post subject: |
|
|
To get the application path in Delphi do
| Code: | | strFilePath := ExtractFilePath(Application.ExeName); //strFilePath is a string |
No idea about the rest.
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Sun Oct 05, 2008 1:11 am Post subject: |
|
|
there is no rest, just add whatever the file name is to the end of that string and run
im failry sure there is an easier way in C# too, that looks odd
_________________
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Oct 05, 2008 1:51 am Post subject: |
|
|
Not sure if this is what you want.
GetModuleFileName returns the path + filename for the calling executable. Simply make the string shorter by a length of what how long the filename is. This returns path.
Then use CreateFile (check return of it) or the function from shlwapi.dll (forgot its name right now) to check whether the file to open is present.
|
|
| Back to top |
|
 |
angerist Grandmaster Cheater Supreme
Reputation: 0
Joined: 18 Jun 2007 Posts: 1011 Location: Australia.
|
Posted: Sun Oct 05, 2008 1:58 am Post subject: |
|
|
Well I'll TRY all of your suggestions and reply. Thankyou
_________________
Last edited by angerist on Sun Oct 05, 2008 10:37 pm; edited 1 time in total |
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Sun Oct 05, 2008 2:49 am Post subject: |
|
|
i think you missed a word there buddy
_________________
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Sun Oct 05, 2008 4:36 am Post subject: |
|
|
I could argue that GetCurrentDirectory is preferable because it takes less parameters. If a programmer forgets that he changed the directory, it's their own fault.
|
|
| Back to top |
|
 |
sponge I'm a spammer
Reputation: 1
Joined: 07 Nov 2006 Posts: 6009
|
Posted: Sun Oct 05, 2008 11:10 am Post subject: |
|
|
Usually when you supply only the file w/ extension, the API should look for it in the same folder.
_________________
|
|
| Back to top |
|
 |
ups2000ups I post too much
Reputation: 0
Joined: 31 Jul 2006 Posts: 2471
|
Posted: Sun Oct 05, 2008 11:38 am Post subject: |
|
|
path := ExtractFilePath(ParamStr(0))+'filename.exe';
_________________
dont complain about my english...
1*1 = 2? |
|
| Back to top |
|
 |
angerist Grandmaster Cheater Supreme
Reputation: 0
Joined: 18 Jun 2007 Posts: 1011 Location: Australia.
|
Posted: Sun Oct 05, 2008 10:39 pm Post subject: |
|
|
I cant really use GetCurrentDirectory its really unstable. I have no control over where people put my app.
_________________
|
|
| Back to top |
|
 |
sponge I'm a spammer
Reputation: 1
Joined: 07 Nov 2006 Posts: 6009
|
Posted: Mon Oct 06, 2008 12:12 am Post subject: |
|
|
| angerist wrote: | | I cant really use GetCurrentDirectory its really unstable. I have no control over where people put my app. | /facepalm. I advise you learn what GetCurrentDirectory does.
_________________
|
|
| Back to top |
|
 |
Wintermoot Expert Cheater
Reputation: 0
Joined: 08 Nov 2007 Posts: 198
|
Posted: Mon Oct 06, 2008 12:40 am Post subject: |
|
|
From what I remember of VB, App.Path works...
@angerist:
C#
| Code: |
Application.StartupPath;
|
VB.NET
| Code: |
Application.StartupPath
|
I have checked that both of those work after using an open file dialog.
|
|
| Back to top |
|
 |
angerist Grandmaster Cheater Supreme
Reputation: 0
Joined: 18 Jun 2007 Posts: 1011 Location: Australia.
|
Posted: Mon Oct 06, 2008 2:01 am Post subject: |
|
|
| sponge wrote: | | angerist wrote: | | I cant really use GetCurrentDirectory its really unstable. I have no control over where people put my app. | /facepalm. I advise you learn what GetCurrentDirectory does. |
Sorry man no need to get stressed out I'm new to programming. I thought GetCurrentDirectory is the last directory that you've been to. But yeh i'll do some research.
_________________
|
|
| Back to top |
|
 |
|