Delphi 链接转换为本地文件路径


本文整理自网络,侵删。

 
//链接转换为本地文件路径
function url2file(url:string):string;
var
  p,i:integer;
  s,dir,fullDir:string; //forcedirectories(mWorkDir);
begin
  s:=url;
  fullDir:=mworkdir;  //程序工作目录;
  if(rightstr(s,1)='/')then s:=s+'index.htm';
  p:=pos(mPort,s);
  if(p>0)then delete(s,p-1,length(mPort)+1);
  p:=pos('/',s);
  dir:=leftstr(s,p-1);
  if(dir='http:')then s:=rightstr(s,length(s)-7);  //去除http头部
  if(dir='https:')then s:=rightstr(s,length(s)-8);  //去除https头部
  p:=pos('/',s);
  dir:=leftstr(s,p-1);
  if(dir<>msite)then s:=msite+s;  //添加主站地址

  p:=pos('/',s);
  while p>0 do begin
    dir:=leftstr(s,p-1);
    fullDir:=fullDir+'\'+dir;
    if(not directoryexists(fullDir))then forcedirectories(fullDir);  //创建本地文件目录
    s:=rightstr(s,length(s)-length(dir)-1);
    p:=pos('/',s);
  end;
  p:=pos('?',s);  //排除链接里面?后面的内容;
  //if(p>0)then s:=replacestr(s,'?','-');
  if(p>0)then s:=leftstr(s,p-1);
  //p:=pos('&',s);  //排除链接里面?后面的内容;
  //if(p>0)then s:=replacestr(s,'&','-');
  //p:=pos('=',s);  //排除链接里面?后面的内容;
  //if(p>0)then s:=replacestr(s,'=','-');
  //if(p>0)then s:=leftstr(s,p-1);
  p:=pos('#',s);  //排除链接里面?后面的内容;
  if(p>0)then s:=leftstr(s,p-1);
  result:=fullDir+'\'+s;
end;

相关阅读 >>

Delphi如何获取系统服务(即service服务程序)列表

Delphi fmx 从app程序直接跳转到支付宝付款转帐页面

Delphi xe6、xe5、xe7在android创建快捷方式

Delphi debug release区别是什么?

Delphi 递归搜索文件夹子目录

Delphi 解析json生成json

Delphi 判断字符是否是汉字,bytetype字符串中判断是否英文

Delphi 修改ie首页代码

Delphi xe5 android手机端转换ansi字符串

python4Delphi 示例应用程序在 Delphi 应用程序中运行简单的 python 脚本

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...