🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages Started by Michele Santucci Wed, 15 Jun 2005 13:50
Paths into URL
#3739
Author: Michele Santucci
Date: Wed, 15 Jun 2005 13:50
19 lines
1286 bytes
Hello NG,

How can I translate a File Path into an URL?
I mean something like that:
    C:\Program files\MyApp\Data\File.txt
into:
    file://C|:/Program files/My App/Data/File.txt

-- 
Michele Santucci
===================
Celin Avio S.r.l.
Software Dev. Manager
--------------------------------------
tel. +390187564080
Via Fontevivo 21/M
19126 La Spezia
=================== 
Re: Paths into URL
#3741
Author: Markus Pesti
Date: Wed, 15 Jun 2005 15:07
43 lines
1769 bytes
Michele Santucci wrote:
> Hello NG,
> 
> How can I translate a File Path into an URL?
> I mean something like that:
>     C:\Program files\MyApp\Data\File.txt
> into:
>     file://C|:/Program files/My App/Data/File.txt
> 

This is not an internet problem but standard c++.
And mind the spaces in file names:

#include <string>
#include <functional>
#include <algorithm>
#include <iostream>

class same : public std::unary_function<char, bool>
{
	char rc;
public:
	same(const char& c) : rc(c) { }
	bool operator() (const char& x) { return x == rc; }
};

int main()
{
	std::string s("C:\\Program Files\\My App\\Data\\File.txt");

	std::string::size_type n = s.find(" ");
	while(n != std::string::npos)
	{
		s.replace(n, 1, "%20");
		n = s.find(" ", n + 3);
	}

	std::replace_if(s.begin(), s.end(), same('\\'), '/');

	s = "file:///" + s;

	std::cout << s << std::endl;
}
Re: Paths into URL
#3742
Author: Remy Lebeau (TeamB)
Date: Wed, 15 Jun 2005 16:49
24 lines
1559 bytes
"Michele Santucci" <michele.santucci@celinavio.it> wrote in message
news:42b0320e$1@newsgroups.borland.com...

> How can I translate a File Path into an URL?

Look at StringReplace(), ie:

    AnsiString Path = "C:\\Program Files\\MyApp\\Data\\File.txt";
    TReplaceFlags flags = TReplaceFlags() << rfReplaceAll;

    AnsiString Temp = StringReplace(Path.SubString(4, MaxInt), "\\", "/",
flags);
    Temp = StringReplace(Temp, " ", "%20", flags);
    // other conversions as needed..

    AnsiString URL;
    URL.sprintf("file://%c|/%s", Path[1], Temp.c_str());

With that said, why do you need to translate it?  HTTP browsers already
recognize normal file paths.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads