View Full Version : (Chapter 16)Delphi 6 Tutorials
_I_Play_Chess
12-06-2003, 09:18 AM
File Management Routines :
Page 1:
<B>Deletefile function:</B>
<I>Deletes a specified file.</I>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> DeleteFile(<B>const</B> sFileName: <B>string</B>): boolean;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Deletes a specified file. DeleteFile returns False if the file specified by sFileName does not exists, or the file cannon be deleted. <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>var myapp : string;
myapp := 'c:\My Doucuments\mp3\my_app.old'
if not Delete(mp3File) then begin
ShowMessage('File not deleted!');
Abort;
end;
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:20 AM
DirectoryExists function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> DirectoryExists(<B>const</B> DirName: <B>string</B>): Boolean; <!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Returns True if a specified directory exists. If DirName specifies a full path name, DirectoryExists searches for the directory along the designated path. Otherwise, the DirName parameter is interpreted as a relative path name from the current directory. <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>var Dir : widestring;
if SelectDirectory('My message','d:\!gajba',Dir) then
showmessage('Folder selected ' + Dir);
//prepare code to use directory 'Dir',
//code ... code
//make sure Dir was not deleted!
if NOT DirectoryExists(Dir) then
begin
ShowMessage('Ups, somebody deleted your folder?! Let's create it again!');
ForceDirectories(Dir);
end;
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:22 AM
DiskFree function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> DiskFree(Drive: Byte): Int64;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Returns the amount of free space in bytes on a specified drive. DiskFree returns -1 if the drive number is invalid. Drive parameter can be set to: 0 = Current drive, 1 = A, 2 = B, 3 = C and so on. <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>//displays a message indicating the number
//of KB free, and what percentage of
//the entire disk space that represents.
var
S: string;
AmtFree: Int64;
Total: Int64;
begin
AmtFree := DiskFree(0);
Total := DiskSize(0);
S := IntToStr(AmtFree div Total) +
'percent of the space on drive 0 is free: ' +
(AmtFree div 1024) + ' Kbytes free. ';
ShowMessage(S);
end;
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:23 AM
DiskSize function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> DiskSize(Drive: Byte): Int64;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Returns the size in bytes of a specified drive. DiskSize returns -1 if the drive number is invalid. Drive parameter can be set to: 0 = Current drive, 1 = A, 2 = B, 3 = C and so on. <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>//displays a message indicating the number
//of KB free, and what percentage of
//the entire disk space that represents.
var
S: string;
AmtFree: Int64;
Total: Int64;
begin
AmtFree := DiskFree(0);
Total := DiskSize(0);
S := IntToStr(AmtFree div Total) +
'percent of the space on drive 0 is free: ' +
(AmtFree div 1024) + ' Kbytes free. ';
ShowMessage(S);
end;
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:29 AM
FileAge function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> FileAge(<B>const</B> aFileName: <B>string</B>): Integer;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Returns the system time stamp of a file. The return value can be converted to a TDateTime object using the FileDateToDateTime function. <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>var aFile : string;
aFileDateTime : TDateTime;
aFileOSDate : integer;
begin
aFile : = Application.ExeName;
aFileOSDate := FileAge(aFile);
if aFileOSDate = -1 then Exit; //invalid file
aFileDateTime := DateAdd(Now,1); //add a day
FileSetDate(aFile, DateTimeToFileDate(aFileDateTime));
//Fo, our application exe file "was" modified tomorow
end;
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:31 AM
FileDateToDateTime function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> FileDateToDateTime(FileDate: Integer): TDateTime; <!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Converts the system time stamp of a file to a TDateTime value. A timestamp is a signed 32-bit integer, used by the OS to record information such as the date and time a file was modified. <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>var aFile : string;
aFileDateTime : TDateTime;
aFileOSDate : integer;
begin
aFile : = Application.ExeName;
aFileOSDate := FileAge(aFile);
if aFileOSDate = -1 then Exit; //invalid file
aFileDateTime := DateAdd(FileDateToDateTime(aFileOSDate),1); //add a day
FileSetDate(aFile, DateTimeToFileDate(aFileDateTime));
//Our application exe file "was" modified one day on the future
end;
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:37 AM
FileExists function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> FileExists(<B>const</B> sFileName: <B>string</B>): boolean;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Checks whether a specified file exists. FileExists returns True if the file specified by sFileName exists, False otherwise. <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>var mp3File : string;
mp3File := 'c:\My Doucuments\mp3\my_song.mp3'
if not FileExists(mp3File) then begin
ShowMessage('MP3 file ' +#13#10 +
mp3File + #13#10 + 'does not exist!');
exit;
end;
</PRE></TD></TR></TBODY></TABLE>
More to go:
Like to know how to write your 1st MP3 DELPHI PLAYER?
well this is a new coming project to start.....
Why not!!! at the end of the Tutorials.
_I_Play_Chess
12-06-2003, 09:40 AM
FileGetAttr function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> FileGetAttr(<B>const</B> sFileName: <B>string</B>): integer;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Retrieves the attributes of a specified file. The resulting value is formed by combining the appropriate file attribute constants:
faReadOnly 1 Read-only files.
faHidden 2 Hidden files
faSysFile 4 System files
faVolumeID 8 Volume ID files
faDirectory 16 Directory files
faArchive 32 Archive files
faSymLink 64 Symbolic link
faAnyFile 71 Any file <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>var mp3File : string;
Attrs : integer;
mp3File := 'c:\My Documents\mp3\my_song.mp3'
Attrs := FileGetAttr(mp3File);
//mark mp3File as hidden (if not hidden already)
if (Attrs and faHidden) = 0 then
FileSetAttr(mp3File, Attrs or faHidden);
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:43 AM
FileSetAttr function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> FileSetAttr(<B>const</B> sFileName: <B>string</B>; Attr : integer): integer;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Sets the attributes of a specified file. FileSetAttr returns 0 (zero) if the function was successful, non-zero value (error code) otherwise. The value of Attr is formed by combining the appropriate file attribute constants:
faReadOnly 1 Read-only files.
faHidden 2 Hidden files
faSysFile 4 System files
faVolumeID 8 Volume ID files
faDirectory 16 Directory files
faArchive 32 Archive files
faSymLink 64 Symbolic link
faAnyFile 71 Any file <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>var mp3File : string;
Attrs : integer;
mp3File := 'c:\My Documents\mp3\my_song.mp3'
Attrs := FileGetAttr(mp3File);
//mark mp3File as hidden (if not hidden already)
if (Attrs and faHidden) = 0 then
FileSetAttr(mp3File, Attrs or faHidden);</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:45 AM
FileSetReadOnly function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> FileSetReadOnly(<B>const</B> sFileName: <B>string</B>; SetReadOnly : boolean): boolean;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Sets the read-only status of the specified file. <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>//make the exe of THIS app read-only
FileSetReadOnly(Application.ExeName, True);
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:46 AM
ForceDirectories function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> ForceDirectories(FolderPath: <B>string</B>): boolean;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Creates all the folders along a given path. The ForceDirectories function creates a directory and all sub-directories that do not already exist. The function returns False if sDir is an empty string or a bad path name, True if succesfull. <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>var sDir : string;
sDir := 'c:\apps\code\free';;
//if sDir path does not exist, create it!
if NOT DirectoryExists(sDir) then
ForceDirectories(sDir);
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:48 AM
GetCurrentDir function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> GetCurrentDir: <B>string</B>;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Returns the name of the current directory. The GetCurrentDir function returns a fully qualified path name for the current working drive and directory. <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>var sCurD : string;
sCurD := GetCurrentDir;
ShowMessage('Current folder: ' + sCurD);
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:50 AM
GetDir function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>procedure</B> GetDir(sDrive: Byte; <B>var</B> sDir:<B>string</B>);
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Returns the name of the current directory for a specified drive. The GetDir function returns a fully qualified path name in sDir for the specified drive in sDrive. The value 0 is used to return the current directory for a current drive. The value of 1 specifies tha A drive, the value of 2 is B drive and so on. The procedure does not check for the existance of a drive specified, if you specify the value of 4 (D drive) sDir would result in D:\ <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>var sCurDirOND : string;
GetDir(4, sCurDirOND);
ShowMessage('Current folder on disk D: ' + sCurDirOND);
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:52 AM
RemoveDir function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> RemoveDir(<B>const</B> DirFullName: <B>string</B>): boolean;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Deletes an empty folder. Returns True if folder was removed, False if not. Note: the directory must be empty before it can be successfully deleted using RemoveDir. <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>//the following example will
//rename the application's file name.
var AFolder : string;
AFolder := 'c:\Temp';
if not RemoveDir(AFolder) then begin
ShowMessage('Could not delete Temp folder');
end;
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:55 AM
RenameFile function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> RenameFile(<B>const</B> FileName, NewFileName: <B>string</B>): boolean;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Changes the name of a specified file. RenameFile returns False if the file specified by FileName cannot be renamed (for example, if the application does not have permission to modify the file). <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>//the following example will
//rename the application's file name.
var thisapp, thisapp_newname : string;
thisapp := Application.ExeName;
thisapp_newname := ExtractFilePath(thisapp) + 'OHOHO_NewName.exe';
if not RenameFile(thisapp, thisapp_newname) then begin
ShowMessage('Could not rename THIS application');
end;
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 09:56 AM
SetCurrentDir function:
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>declaration</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE><B>function</B> SetCurrentDir(<B>const</B> sNewDir:<B>string</B>): boolean;
<!-- end declaratrion --><!-- begin description -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>description</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>Sets the current directory. Function returns True if the directory specified in sNewDir was successfully set as the curent, False otherwise. <!-- end description --><!-- begin example -->
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD bgColor=#c0c0c0><B>example</B></TD></TR></TR>
<TR>
<TD bgColor=#000000 height=1></TD></TR>
<TR>
<TD height=2></TD></TR></TBODY></TABLE>
<TABLE width="100%" bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD><PRE>var sAppDir : string;
//app path
sAppDir := ExtractFileDir(ParamStr(0));
if Not SetCurrentDir(sAppDir) then
raise Exception.Create
('Unable to set current dir.');
</PRE></TD></TR></TBODY></TABLE>
_I_Play_Chess
12-06-2003, 10:02 AM
How to write your 1st MP3 player in DELPHI?
vBulletin v3.5.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.