procedure MakeDir(Dir: String);
  function Last(What: String; Where: String): Integer;
  var
    Ind : Integer;
  begin
    Result := 0;
    for Ind := (Length(Where)-Length(What)+1) downto 1 do
        if Copy(Where, Ind, Length(What)) = What then begin
           Result := Ind;
           Break;
        end;
  end;
 var
  PrevDir : String;
  Ind     : Integer;
 begin
  if Copy(Dir,2,1) <> ':' then
     if Copy(Dir,3,1) <> '\' then
        if Copy(Dir,1,1) = '\' then
           Dir := 'C:'+Dir
        else
           Dir := 'C:\'+Dir
     else
        Dir := 'C:'+Dir;  if not DirectoryExists(Dir) then begin
     // 如果目录不存在,取得上一个目录名
     Ind     := Last('\', Dir);        //  最后一个 '\'的位置
     PrevDir := Copy(Dir, 1, Ind-1);   //  上一个目录
     // 如果上一个目录不存在
     // 传递给此递归过程
     if not DirectoryExists(PrevDir) then
        MakeDir(PrevDir);
     // 在这里,上一个目录必须存在
     // 创建(in "Dir"; variable)目录
     CreateDir(Dir);
  end;
 end; 
//这是一个创建目录树的程序,请帮我转为BCB的代码,各位如果有更好的方法也可以另写出来(请用BCB),谢谢!

解决方案 »

  1.   

    或能用CreateDir生成多层文件夹的程序都可以,方法不限,语言限BCB,因为我是BCB和DELPHI的新手,谢谢!
      

  2.   

    直接把包含此函数的.pas文件添加到project里来!!!
      

  3.   

    老兄,不必自已写,SysUtils中有这个函数:
    if (ForceDirectories("C:\\noPath\\hello\\good\\"))
      ShowMessage("OK");
      

  4.   

    谢谢您copy_paste(木石三) ,顺便问一下,您对二进制文件的加密研究如何,
    http://expert.csdn.net/Expert/topic/1150/1150664.xml?temp=.1504022
    我的这个问题解决后,想把生成的二进制文件加密,不知道您能做吗?我开个帖子来请教您如何?
      

  5.   


    typedef void __stdcall (*TOnDataProc)(BYTE* data, int count);#define KeyA 0xDB00
    #define KeyB 0xFD00void __stdcall EncrytData(BYTE* data, int count)
    {
      int i;
      WORD key = 0;
      BYTE* p = data;
      for (i = 0; i < count; i ++, p ++)
      {
        *p = *p ^ (key >> 8);
        key = (*p + key) * KeyA + KeyB;
      }
    }void __stdcall DecrytData(BYTE* data, int count)
    {
      int i;
      WORD key = 0;
      BYTE b, *p = data;
      for (i = 0; i < count; i ++, p++)
      {
        b = *p;
        *p = b ^ (key >> 8);
        key = (b + key) * KeyA + KeyB;
      }
    }void FileProc(String FileName, TOnDataProc OnDataProc)
    {
      TFileStream* Stream = new TFileStream(FileName, fmOpenReadWrite);
      try
      {
        BYTE Buffer[0x1000];
        __int64 CurrentPos;
        int i, RetLen, FileSize = Stream->Size, Count = sizeof(Buffer);
        while (FileSize > 0)
        {
          CurrentPos = Stream->Position;
          RetLen = Stream->Read(Buffer, Count);
          OnDataProc(Buffer, RetLen);
          Stream->Position = CurrentPos;
          Stream->WriteBuffer(Buffer, RetLen);
          FileSize -= RetLen;
        }
      }
      __finally
      {
        delete Stream;
      }
    }void __fastcall TForm1::Button1Click(TObject *Sender)
    {
      FileProc(Edit1->Text, &EncrytData);
    }void __fastcall TForm1::Button2Click(TObject *Sender)
    {
      FileProc(Edit1->Text, &DecrytData);
    }//拿个文本文件试试,你看行不行