Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get Files from URL-Folder?

851 views
Skip to first unread message

Stephan Schneider

unread,
Aug 18, 2004, 12:13:20 PM8/18/04
to
Hallo,

Env.: Delphi 6 Ent. UP2

I've a function GetFilesFromFolder(const Directory, FileMask: String; Files:
TStrings). This function determines all files in Files stringlist within a
folder (=Directory), specified thru FileMask. So far so good.

But what is to do, if Directory is an URL? How is the implementation, to get
all files from an "URL-Folder"?
If you have any source code for this, it would be great.

Kind regards
Stephan


Finn Tolderlund

unread,
Aug 18, 2004, 12:46:50 PM8/18/04
to
Don't you mean UNC path?
If so then FindFirst/FindNext/FindClose work just fine.
--
Finn Tolderlund


"Stephan Schneider" <stephan....@web.de> skrev i en meddelelse
news:4123...@newsgroups.borland.com...

Stephan Schneider

unread,
Aug 18, 2004, 12:58:50 PM8/18/04
to
I really mean URL, not UNC!
Thanks
Stephan

"Finn Tolderlund" <n...@spam.dk> schrieb im Newsbeitrag
news:412387df$2...@newsgroups.borland.com...

Remy Lebeau (TeamB)

unread,
Aug 18, 2004, 2:27:30 PM8/18/04
to

"Stephan Schneider" <stephan....@web.de> wrote in message
news:4123...@newsgroups.borland.com...

> I really mean URL, not UNC!

If you mean an HTTP URL, then there is no way to do what you are asking for.
HTTP Does not support enumerating files on a remote server.

What EXACTLY are you trying to accomplish? Please provide more details.


Gambit


Stephan Schneider

unread,
Aug 18, 2004, 3:30:37 PM8/18/04
to
> Your only hope is if the remote HTTP server has been configured to
> display directory listings

This is the case! When I click on the source code of my browser, I see, that
the Webserver returns a simple HTML file, where all files are listed. Does
this mean, that I've to parse the HTML content for this files?

Stephan


Remy Lebeau (TeamB)

unread,
Aug 18, 2004, 4:05:10 PM8/18/04
to

"Stephan Schneider" <stephan....@web.de> wrote in message
news:4123ae59$1...@newsgroups.borland.com...

> Does this mean, that I've to parse the HTML content for this files?

Yes.


Gambit


eshipman

unread,
Aug 18, 2004, 3:34:36 PM8/18/04
to
In article <4123...@newsgroups.borland.com>, stephan....@web.de
says...
> More Details:
> I've an URL for remote access, e.g. http://www.anyurl.com/my/
>
> On this adress there a different folders, e.g.
> http://www.anyurl.com/my/dir1
> http://www.anyurl.com/my/dir2
> http://www.anyurl.com/my/dir3
>
> In every folder, there are files. Now I want to write a method, where I can
> specify the URL and where I get the files.
> e.g. GetFilesFromURL('http://www.anyurl.com/my/dir2', Files);
>
> Files is a TStringList, where all filenames should be stored.

If you have access to the server in question, you will have to permit
directory listings. Then you can use idHTTP to do a get on the
directory, thus returning a directory list in HTML, Then you would have
to parse the HTML directory to build your file list.

This will build your file list for you:

const
SiteURL = 'http://66.45.227.243/~austin1/forms/';

procedure ParseHTMLDirectory(HTML:String; var sl: TStringList);
var
IDoc: IHTMLDocument2;
v: Variant;
ovLink: IHTMLAnchorElement;
x: Integer;
ovTags: IHTMLElementCollection;
s: String;
begin
Idoc:=CreateComObject(Class_HTMLDocument) as IHTMLDocument2;
try
IDoc.designMode:='on';
while IDoc.readyState<>'complete' do
Application.ProcessMessages;
v:=VarArrayCreate([0,0],VarVariant);
v[0]:= HTML;
IDoc.write(PSafeArray(System.TVarData(v).VArray));
IDoc.designMode:='off';
while IDoc.readyState<>'complete' do
Application.ProcessMessages;
// Iterate through the Links
ovTags := (iDoc.all.tags('A') as IHTMLElementCollection);
for x := 0 to ovTags.length -1 do
begin
ovLink := (ovTags.item(x, 0) as IHTMLAnchorElement);
if Pos('?', ovLink.href) = 0 then
begin
// about:blank gets prepended to the href so
// let's remove it if it is there
s := ovLink.href;
if Pos('about:blank', s) > 0 then
s := SiteURL + Copy(s, 12, Length(s));
sl.Add(s);
end;
end;
finally
IDoc := nil;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
sl: TStringList;
begin
sl := TStringList.Create;
ParseHTMLDirectory(idHTTP1.Get(SiteURL), sl);
// Delete the first entry, comment out to see what it is.
sl.Delete(0);
ListBox1.Items.Assign(sl);
end;

eshipman

unread,
Aug 18, 2004, 3:36:55 PM8/18/04
to
<SNIP>

> If you have access to the server in question, you will have to permit
> directory listings. Then you can use idHTTP to do a get on the
> directory, thus returning a directory list in HTML, Then you would have
> to parse the HTML directory to build your file list.
>
<SNIP>

Place ActiveX, COMObj, and mshtml in your uses.

Stephan Schneider

unread,
Aug 19, 2004, 4:04:06 AM8/19/04
to
Thanks a lot, works fine!

"eshipman" <mr_delphi_developer@yahoo!!!.com> schrieb im Newsbeitrag
news:MPG.1b8d6bc4c...@forums.borland.com...

Ralf Junker

unread,
Aug 19, 2004, 8:25:09 AM8/19/04
to
If you prefer a pure Delphi (non-Internet explorer) solution, you can use my
DIHtmlParser component. It includes an example project which does exactly what
you need.

DIHtmlParser is fully Unicode and generally faster than the Internet Explorer
parser. It observes the <BASE href...> tag and fully resolves relative to
absolute path names.

Download is from my web-site: http://www.yunqa.de/delphi/

Regards,

Ralf

覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧
Stephan Schneider wrote:

>More Details:
>I've an URL for remote access, e.g. http://www.anyurl.com/my/
>
>On this adress there a different folders, e.g.
>http://www.anyurl.com/my/dir1
>http://www.anyurl.com/my/dir2
>http://www.anyurl.com/my/dir3
>
>In every folder, there are files. Now I want to write a method, where I can
>specify the URL and where I get the files.
>e.g. GetFilesFromURL('http://www.anyurl.com/my/dir2', Files);
>
>Files is a TStringList, where all filenames should be stored.

----------
The Delphi Inspiration
http://www.yunqa.de/delphi/

0 new messages