if(dataArray[i]!
=FileStream.ReadByte()){
//写入数据错误
return;
}
}
//"数据流"+FileStream.Name+"已验证"
}
10.读取文件属性
//usingSystem.IO;
FileInfof=newFileInfo(%%1);//f.CreationTime,f.FullName
if((f.Attributes&FileAttributes.ReadOnly)!
=0){
%%2
}
else{
%%3
}
11.写入属性
//usingSystem.IO;
FileInfof=newFileInfo(%%1);
//设置只读
f.Attributes=myFile.Attributes|FileAttributes.ReadOnly;
//设置可写
f.Attributes=myFile.Attributes&~FileAttributes.ReadOnly;
12.枚举一个文件夹中的所有文件夹
//usingSystem.IO;
foreach(string%%2inDirectory.GetDirectories(%%1)){
%%3
}
/*
DirectoryInfodir=newDirectoryInfo(%%1);
FileInfo[]files=dir.GetFiles("*.*");
foreach(FileInfo%%2infiles){
%%3
}
*/
13.复制文件夹
/*
usingSystem.IO;
usingSystem.Collections;
*/
stringpath=(%%2.LastIndexOf(Path.DirectorySeparatorChar)==%%2.Length-1)?
%%2:
%%2+Path.DirectorySeparatorChar;
stringparent=Path.GetDirectoryName(%%1);
Directory.CreateDirectory(path+Path.GetFileName(%%1));
DirectoryInfodir=newDirectoryInfo((%%1.LastIndexOf(Path.DirectorySeparatorChar)==%%1.Length-1)?
%%1:
%%1+Path.DirectorySeparatorChar);
FileSystemInfo[]fileArr=dir.GetFileSystemInfos();
QueueFolders=newQueue(dir.GetFileSystemInfos());
while(Folders.Count>0)
{
FileSystemInfotmp=Folders.Dequeue();
FileInfof=tmpasFileInfo;
if(f==null)
{
DirectoryInfod=tmpasDirectoryInfo;
Directory.CreateDirectory(d.FullName.Replace((parent.LastIndexOf(Path.DirectorySeparatorChar)==parent.Length-1)?
parent:
parent+Path.DirectorySeparatorChar,path));
foreach(FileSystemInfofiind.GetFileSystemInfos())
{
Folders.Enqueue(fi);
}
}
else
{
f.CopyTo(f.FullName.Replace(parent,path));
}
}
14.复制目录下所有的文件夹到另一个文件夹下
/*
usingSystem.IO;
usingSystem.Collections;
*/
DirectoryInfod=newDirectoryInfo(%%1);
foreach(DirectoryInfodirsind.GetDirectories())
{
Queueal=newQueue(dirs.GetFileSystemInfos());
while(al.Count>0)
{
FileSystemInfotemp=al.Dequeue();
FileInfofile=tempasFileInfo;
if(file==null)
{
DirectoryInfodirectory=tempasDirectoryInfo;
Directory.CreateDirectory(path+directory.Name);
foreach(FileSystemInfofsiindirectory.GetFileSystemInfos())
al.Enqueue(fsi);
}
else
File.Copy(file.FullName,path+file.Name);
}
}
15.移动文件夹
/*
usingSystem.IO;
usingSystem.Collections;
*/
stringfilename=Path.GetFileName(%%1);
stringpath=(%%2.LastIndexOf(Path.DirectorySeparatorChar)==%%2.Length-1)?
%%2:
%%2+Path.DirectorySeparatorChar;
if(Path.GetPathRoot(%%1)==Path.GetPathRoot(%%2))
Directory.Move(%%1,path+filename);
else
{
stringparent=Path.GetDirectoryName(%%1);
Directory.CreateDirectory(path+Path.GetFileName(%%1));
DirectoryInfodir=newDirectoryInfo((%%1.LastIndexOf(Path.DirectorySeparatorChar)==%%1.Length-1)?
%%1:
%%1+Path.DirectorySeparatorChar);
FileSystemInfo[]fileArr=dir.GetFileSystemInfos();
QueueFolders=newQueue(dir.GetFileSystemInfos());
while(Folders.Count>0)
{
FileSystemInfotmp=Folders.Dequeue();
FileInfof=tmpasFileInfo;
if(f==null)
{
DirectoryInfod=tmpasDirectoryInfo;
DirectoryInfodpath=newDirectoryInfo(d.FullName.Replace((parent.LastIndexOf(Path.DirectorySeparatorChar)==parent.Length-1)?
parent:
parent+Path.DirectorySeparatorChar,path));
dpath.Create();
foreach(FileSystemInfofiind.GetFileSystemInfos())
{
Folders.Enqueue(fi);
}
}
else
{
f.MoveTo(f.FullName.Replace(parent,path));
}
}
Directory.Delete(%%1,true);
}
16.移动目录下所有的文件夹到另一个目录下
/*
usingSystem.IO;
usingSystem.Collections;
*/
stringfilename=Path.GetFileName(%%1);
if(Path.GetPathRoot(%%1)==Path.GetPathRoot(%%2))
foreach(stringdirinDirectory.GetDirectories(%%1))
Directory.Move(dir,Path.Combine(%%2,filename));
else
{
foreach(stringdir2inDirectory.GetDirectories(%%1))
{
stringparent=Path.GetDirectoryName(dir2);
Directory.CreateDirectory(Path.Combine(%%2,Path.GetFileName(dir2)));
stringdir=(dir2.LastIndexOf(Path.DirectorySeparatorChar)==dir2.Length-1)?
dir2:
dir2+Path.DirectorySeparatorChar;
DirectoryInfodirdir=newDirectoryInfo(dir);
FileSystemInfo[]fileArr=dirdir.GetFileSystemInfos();
QueueFolders=newQueue(dirdir.GetFileSystemInfos());
while(Folders.Count>0)
{
FileSystemInfotmp=Folders.Dequeue();
FileInfof=tmpasFileInfo;
if(f==null)
{
DirectoryInfod=tmpasDirectoryInfo;
DirectoryInfodpath=newDirectoryInfo(d.FullName.Replace((parent.LastIndexOf(Path.DirectorySeparatorChar)==parent.Length-1)?
parent:
parent+Path.DirectorySeparatorChar,%%2));
dpath.Create();
foreach(FileSystemInfofiind.GetFileSystemInfos())
{
Folders.Enqueue(fi);
}
}
else
{
f.MoveTo(f.FullName.Replace(parent,%%2));
}
}
dirdir.Delete(true);
}
}
17.以一个文件夹的框架在另一个目录创建文件夹和空文件
/*
usingSystem.IO;
usingSystem.Collections;
*/
boolb=false;
stringpath=(%%2.LastIndexOf(Path.DirectorySeparatorChar)==%%2.Length-1)?
%%2:
%%2+Path.DirectorySeparatorChar;
stringparent=Path.GetDirectoryName(%%1);
Directory.CreateDirectory(path+Path.GetFileName(%%1));
DirectoryInfodir=newDirectoryInfo((%%1.LastIndexOf(Path.DirectorySeparatorChar)==%%1.Length-1)?
%%1:
%%1+Path.DirectorySeparatorChar);
FileSystemInfo[]fileArr=dir.GetFileSystemInfos();
QueueFolders=newQueue(dir.GetFileSystemInfos());
while(Folders.Count>0)
{
FileSystemInfotmp=Folders.Dequeue();
FileInfof=tmpasFileInfo;
if(f==null)
{
DirectoryInfod=tmpasDirectoryInfo;
Directory.CreateDirectory(d.FullName.Replace((parent.LastIndexOf(Path.DirectorySeparatorChar)==parent.Length-1)?
parent:
parent+Path.DirectorySeparatorChar,path));
foreach(FileSystemInfofiind.GetFileSystemInfos())
{
Folders.Enqueue(fi);
}
}
else
{
if(b)File.Create(f.FullName.Replace(parent,path));
}
}
18.复制文件
//usingSystem.IO;
File.Copy(%%1,%%2);
19.复制一个文件夹下所有的文件到另一个目录
//usingSystem.IO;
foreach(stringfileStrinDirectory.GetFiles(%%1))
File.Copy((%%1.LastIndexOf(Path.DirectorySeparatorChar)==%%1.Length-1)?
%%1+Path.GetFileName(fileStr):
%%1+Path.DirectorySeparatorChar+Path.GetFileName(fileStr),(%%2.LastIndexOf(Path.DirectorySeparatorChar)==%%2.Length-1)?
%%2+Path.GetFileName(fileStr):
%%2+Path.DirectorySeparatorChar+Path.GetFileName(fileStr));
20.提取扩展名
//usingSystem.IO;
string%%2=Path.GetExtension(%%1);
21.提取文件名
//usingSystem.IO;
string%%2=Path.GetFileName(%%1);
22.提取文件路径
//usingSystem.IO;
string%%2=Path.GetDirectoryName(%%1);
23.替换扩展名
//usingSystem.IO;
File.ChangeExtension(%%1,%%2);
24.追加路径
//usingSystem.IO;
string%%3=Path.Combine(%%1,%%2);
25.移动文件
//usingSystem.IO;
File.Move(%%1,%%2+Path.DirectorySeparatorChar+file.getname(%%1));
26.移动一个文件夹下所有文件到另一个目录
//usingSystem.IO;
foreach(stringfileStrinDirectory.GetFiles(%%1))
File.Move((%%1.LastIndexOf(Path.DirectorySeparatorChar)==%%1.Length-1)?
%%1+Path.GetFileName(fileStr):
%%1+Path.DirectorySeparatorChar+Path.GetFileName(fileStr),(%%2.LastIndexOf(Path.DirectorySeparatorChar)==%%2.Length-1)?
%%2+Path.GetFileName(fileStr):
%%2+Path.DirectorySeparatorChar+Path.GetFileName(fileStr));
27.指定目录下搜索文件
/*
usingSystem.Text;
usingSystem.IO;
*/
stringfileName=%%1;
DriveInfo[]drives=DriveInfo.GetDrives();
stringparent=Path.GetDirectoryName(%%2);
DirectoryInfodir=newDirectoryInfo((%%2.LastIndexOf(Path.DirectorySeparatorChar)==%%2.Length-1)?
%%2:
%%2+Path.DirectorySeparatorChar);
FileSystemInfo[]fileArr;
try
{
fileArr=dir.GetFileSystemInfos();
}
catch(Exception)
{
continue;
}
QueueFolders=newQueue(dir.GetF