Static File class:
Methods included:
Exists (filename)-check whether the specified file exists.
Copy ("thesource file", "the new file") -- copy the file from the original location to the target location
Create () -- create a file from a specified path
Delete () -- delete an object
Open () -- returns the filestream object from the specified path
Move () -- move the specified file to a new location. You can specify different names for the file in the new location!
Fileinfo is a non-static class. No static method!
Obtain a Logical Disk:
String [] driver = directory. getlogicaldrives ();
Get ApplicationProgramCurrent working directory
String Path = directory. getcurrentdirectory ();
Get the name of the subdirectory:
String filename = path. getfilename (@ "D: \ TXT \ txt.txt"); // return txt.txt
Get the list of file names in the directory
String [] getf = directory. getfiles (@ "D: \ TXT \");
Code
Using System;
Using System. Collections. Generic;
Using System. text;
Using System. IO;
Namespace Leleapplication1
{
Class Program
{
Static Void Main ( String [] ARGs)
{
Fileinfotest ();
Filetest ();
Dirt ();
Console. readkey ();
}
Static Void Fileinfotest ()
{
Fileinfo fl = New Fileinfo ( @" D: \ TXT \ txt.txt " );
If (FL. exists)
{
Console. writeline ( " The file exist! " );
}
Else
{
Console. writeline ( " The fiel is not exist! " );
}
}
Static Void Filetest ()
{
If (File. exists ( @" D: \ TXT \ txt.txt " ))
{
Console. writeline ( " The file is exist, it was checked by the static class file! " );
// File. Copy (@ "D: \ TXT \ txt.txt", @ "D: \ TXT \ XX \ t.txt ");
}
Else
{
Console. writeline ( " The file is not exist! " );
}
}
Static Void Dirt ()
{
String [] Driver = Directory. getlogicaldrives ();
String Path = Directory. getcurrentdirectory ();
Console. writeline (PATH );
String Filename = Path. getfilename ( @" D: \ TXT \ txt.txt " );
String [] Getf = Directory. getfiles ( @" D: \ TXT \ " );
Foreach ( String Name In Getf)
{
Console. writeline (name );
}
Console. writeline ( " The file name is {0} " , Filename );
Foreach ( String ARG In Driver)
{
Console. writeline (ARG );
}
}
Static Void Createdirt ()
{
Directoryinfo dirin = New Directoryinfo ();
}
}
}