procedure TForm1.IdFTPServer1ChangeDirectory(ASender: TIdFTPServerThread; var VDirectory: String); {*将目录调整为上一级目录*} Function EraseLastString(Source:String;EraseChar:Char):String; var BasePoint,DymaPoint:integer; StrLen:Integer; begin StrLen:=Length(Source); if StrLen<=0 then Result:=Source; //已经是根目录 DymaPoint:=-1; //初始化指针 for BasePoint:=1 to StrLen do begin if Source[BasePoint]=EraseChar then DymaPoint:=BasePoint; //定位目录分隔字符 end; if DymaPoint=-1 then begin Result:=EraseChar end else begin SetLength(Source,DymaPoint-1); Result:=Source; end; end;var CurrentDir:String; begin CurrentDir:=ASender.CurrentDir ; {判断当前的目录是否为根目录} If VDirectory='..\' then begin VDirectory:=EraseLastString(CurrentDir,'\'); end;end;
这个是我在上传文件时来判断要放在服务器的哪个文件夹里面的代码 procedure TFServer.IdFTPServer1StoreFile(ASender: TIdFTPServerThread; const AFileName: String; AAppend: Boolean; var VStream: TStream); var NewFile:String; begin //将FTP中使用的目录符号“/”转换为Windows中的目录符号 “\” NewFile :=ChangeFolderChar(WorkDirectory.Text+AFileName); //在FTP服务器中建立相应文件,并指定该文件的访问接口 VStream:=TFileStream.Create(NewFile,fmCreate); end;Function ChangeFolderChar(Str:String):String; //将FTP中使用的目录符号“/”转换为Windows中的目录符号 “\”的函数 var I:Integer; mystr : string; begin For I:=0 to length(Str)-1 do begin if Str[I]='/' then Str[I]:='\'; end; Result:=Str; end;然后执行以后newfile不对正常的是C:\文件夹\a.txt这里变成了C:\\\文件夹\a.txt然后就报错无法找到这个目录,你看看能不能帮帮我啊
var VDirectory: String);
{*将目录调整为上一级目录*}
Function EraseLastString(Source:String;EraseChar:Char):String;
var
BasePoint,DymaPoint:integer;
StrLen:Integer;
begin
StrLen:=Length(Source);
if StrLen<=0 then
Result:=Source;
//已经是根目录
DymaPoint:=-1;
//初始化指针
for BasePoint:=1 to StrLen do
begin
if Source[BasePoint]=EraseChar then
DymaPoint:=BasePoint;
//定位目录分隔字符
end;
if DymaPoint=-1 then
begin
Result:=EraseChar
end
else
begin
SetLength(Source,DymaPoint-1);
Result:=Source;
end;
end;var
CurrentDir:String;
begin
CurrentDir:=ASender.CurrentDir ;
{判断当前的目录是否为根目录}
If VDirectory='..\' then
begin
VDirectory:=EraseLastString(CurrentDir,'\');
end;end;
procedure TFServer.IdFTPServer1StoreFile(ASender: TIdFTPServerThread;
const AFileName: String; AAppend: Boolean; var VStream: TStream);
var
NewFile:String;
begin
//将FTP中使用的目录符号“/”转换为Windows中的目录符号 “\”
NewFile :=ChangeFolderChar(WorkDirectory.Text+AFileName);
//在FTP服务器中建立相应文件,并指定该文件的访问接口
VStream:=TFileStream.Create(NewFile,fmCreate);
end;Function ChangeFolderChar(Str:String):String;
//将FTP中使用的目录符号“/”转换为Windows中的目录符号 “\”的函数
var
I:Integer;
mystr : string;
begin
For I:=0 to length(Str)-1 do
begin
if Str[I]='/' then
Str[I]:='\';
end;
Result:=Str;
end;然后执行以后newfile不对正常的是C:\文件夹\a.txt这里变成了C:\\\文件夹\a.txt然后就报错无法找到这个目录,你看看能不能帮帮我啊