比如说:
assignfile(f,'c:\my documents\newfile.txt');
如果 c:\my documents\ 目录不存在就会产生一个错误,如何防止呢?如何创建一个目录呢?

解决方案 »

  1.   

    try something likestrFolderName  = "c:\my documents"
    if Dir(strFolderName, vbDirectory) <> "" then
      '存在
    else
       Call MkDir(strFolderName)
    end if
      

  2.   

    oops, sorry, that was in VB, :-)use DirectoryExists to checkuse CreateDir or ForceDirectories to create a new folder
      

  3.   

    saucer(思归) 大侠真的很厉害!!!
    你是我的 CSDN 中的偶像之一。
      

  4.   

    if not DirectoryExists(path.Dirvector) then
                     if not CreateDir(path.Dirvector) then
                     begin
                          raise Exception.Create('不能建立路径:'+ Path);
                     end;
      

  5.   

    数牛X人物,还看[saucer(思归)]。向他学习!
      

  6.   

    我一般还是用directoryexists比较好用些
      

  7.   

    ForceDirectories:创建目录,包括该目录包含的任何父目录,如果不存在,各层路径都会加以创建。
    DirectoryExists:判断目录是否存在。
    ProcessPath:分解全路径为盘符、路径、文件名。
    FileExists:判断文件是否存在。
    DeleteFile:删除文件。
    ChangeFileExt:修改文件后缀。
    RenameFile:重命名文件。
    ExtractFilePath:取得文件的路径。   Example:    ExtractFilePath(Application.ExeName)CreateDir创建一个新的路径
    mkdir创建一个新的子目录