delphi 链接转换为本地文件路径  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.042366981506348 seconds