File Management functions (1)

Source: Internet
Author: User
// Determine whether the file existsvar F: string; begin F: = 'C: \ temp \ test.txt '; if not fileexists (f) then begin // if the file does not exist end; end;
  
   
 // Determine whether the folder contains directoryexistsvar dir: string; begin dir: = 'C: \ Temp '; if not directoryexists (DIR) then begin // If the folder does not exist end;
  
   
 // Delete the deletefile; windows. deletefilevar F: string; begin F: = 'C: \ temp \ test.txt '; // deletefile (f); // return Boolean // or use the system API: Windows. deletefile (pchar (f); // return booleanend;
  
   
 // Delete the folder removedir; removedirectoryvar dir: string; begin dir: = 'C: \ Temp '; removedir (DIR); // return Boolean // or use the system API: removedirectory (pchar (DIR); // return booleanend;
  
   
 // Get the current folder getcurrentdirvar dir: string; begin dir: = getcurrentdir; showmessage (DIR); // C: \ Documents and Settings \ WY \ My Documents ents \ rad studio \ projectsend;
  
   
 // Set the current folder setcurrentdir; chdir; setcurrentdirectoryvar dir: string; begin dir: = 'C: \ Temp '; If setcurrentdir (DIR) Then showmessage (getcurrentdir); // C: \ Temp // or chdir (DIR); // No return value // you can also use API: setcurrentdirectory (pchar (DIR); // return booleanend;
  
   
 // Obtain the current path name of the specified drive. getdirvar dir: string; B: byte; begin B: = 0; getdir (B, DIR); showmessage (DIR ); /// the first parameter: 1, 2, 3, 4... corresponding to: a, B, c, d... // 0 is the default drive end;
  
   
 // Renamefilevar oldname, newname: string; begin oldname: = 'C: \ temp \ old.txt '; newname: = 'C: \ temp \ new.txt '; if renamefile (oldname, newname) Then showmessage ('renamed successfully! '); // You can also: setcurrentdir ('C: \ Temp'); oldname: = 'old.txt '; newname: = 'new.txt'; If renamefile (oldname, newname) then showmessage ('renamed successfully! '); End;
  
   
 // Create the folder createdir; createdirectory; forcedirectoriesvar dir: string; begin dir: = 'C: \ temp \ Delphi '; if not directoryexists (DIR) Then createdir (DIR ); // return Boolean // You can also directly use API: createdirectory (pchar (DIR), nil); // return Boolean // if the upper-level directory is missing, the system will automatically complete: Dir: = 'C: \ temp \ codegear \ Delphi \ 2007 \ '; forcedirectories (DIR); // return booleanend;
  
   
 // Delete the empty folder removedir; removedirectoryvar dir: string; begin dir: = 'C: \ temp \ Delphi '; removedir (DIR ); // return Boolean // you can also use API: removedirectory (pchar (DIR); // return booleanend;
  
   
 // Create a new file, filecreatevar filename: string; I: integer; begin filename: = 'C: \ temp \ test. dat '; I: = filecreate (filename); If I> 0 then showmessage ('the new file handle is:' + inttostr (I) else showmessage ('creation failed! '); End;
  
   
 // Obtain the current file version number getfileversionvar S: string; I: integer; begin S: = 'C: \ windows \ notepad.exe '; I: = getfileversion (s ); // if there is no version number, return-1 showmessage (inttostr (I); // 327681 this is the version number of the current notepad (you should also convert it) end;
  
   
 // Obtain the disk space disksize; diskfreevar R: real; s: string; Begin R: = disksize (3); // obtain C: total space, in the unit of byte R: = r/1024/1024/1024; STR (r: 0: 2, s); // The string S: = 'C disk total space is: '+ S + 'gb'; showmessage (s); // xx. xx gb r: = diskfree (3); // get C: available space R: = r/1024/1024/1024; STR (r: 0: 2, s); s: = 'C disk available space: '+ S + 'gb'; showmessage (s); // xx. XX gbend; // interfaces-file management functions (2)
  
   
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.