Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i extract source code path in delphi?

Status
Not open for further replies.

chandu17

Programmer
Mar 28, 2010
4
US
I need one help regarding extract path. plz help me.

I have source code in network drive. for example "Z:\Code\".

i want copy "Sample.xml" file (It is there in Z:\Code\) to output directory where ".exe" file is exist.

can any one help me how to extract "Z:\code" path.

Thanks in advance.
 
You haven't provide much information so its hard to guess what level you are at, but at a basic level..

If you know the filenames then you can use 'iffileexists' function to test if the files are present, more likely you will need to use the 'findfirst' and 'findnext' functions to search through your remote folders (I think there are FAQ's that will explain how to do this) once you have located the files copy them with copyfile (API).

The Delphi Help states that there are no Delphi library routines that help you do this, in fact there are in a file called fmxutils.pas which is located in 'Demos/doc/filemanex'

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
hi sggaunt,

Thank you for responding.

But here my scenario is different. The file "Sample.xml" is exist all network drivers (which ever n/w drives are assigned to machine). if application is using "Z:\Code\" then path := 'Z:\code', if application is using "Y:\Code\" then path := "Y:\Code\" etc..

Basically i want the information about source code path irrespective of file.

please help me.
Thanq advance.
 
I think I am more confused now!
I take it from the example "Sample.xml" that we are not talking about Delphi source files but files that your Delphi application is accessing on network machines?

If so my questions are.
If the application is already accessing one of these file, how did that allocation happen if you don't have the path information already?

If your application is attempting to access one of these similarly named files, does it matter which one it accesses?

If it just needs to find the first one (because not all the network places will be active) then there are ways to do this.
Map the drives on you network, i.e assign a letter to each network drive visible and use iffileexists to loop through them. again there is information in the FAQ's on how to do this.
Use one of the network aware components like TShellTreeView, this has methods that allow searching.
My main application that need to access network files has been converted from drive mapping to use TShellTreeview, because it is much faster and easier to maintain.


Other than that we might need more info on what it is you are trying to do?




Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
if you want only the path from an existing filename you can use the ExtractFilePath function from the sysutils unit.

Code:
uses SysUtils,...


...

procedure TestIt(str : string);
begin
 str := ExtractFilePath(str);
end;

TestIt('z:\code\sample.xml') will return 'z:\code'

/Daddy


-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Here scenario is different. i am repeating my question.

my application code is there following drives:
V:\code
W:\code
X:\code
Y:\Code
Z:\Code
Assume that all drives are assigned and each drives contain their own sample.xml file.
And My outfile is there in D:\Output.

At run time i want to copy sample.xml file to D:\Output.

for eg if application uses V:\code then i want to copy V:\code\Sample.xml --> D:\Output
application uses Z:\code then v:\code\Sample.xml --> D:\Output and etc.. Here i want to retrieve source path runtime.

My question is how to retrieve source code path ie V:\code or Z:\Code etc. Here i can't use FileExist bcz each drive contains own sample.xml.

Daddy, i can't use your function bcz application don't know the where sample.xml exist.

i tried with ParamStr(0), Application.exe, GetCurDir, GetDir and CmdLine. all this functions giving 'D:\Output'.

Plz help me regarding this.

 
if I understand it correctly,

you are starting your application from D:\output ?

are you giving the xml path as a parameter to your application? (eg: d:\output\yourapp.exe "z:\code\")

then ParamStr(1) will contain what you need.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top