//
file_sys_0.cpp : Defines the entry point for the console application.
//
#include " stdafx.h "
#include < cstdlib >
#include < iostream >
#include < io.h >
#include < direct.h >
using namespace std;
const char * to_search = " ..\\temp\\*.* " ; // 查找当前文件夹下temp文件夹下的所有文件或文件夹
int main( int argc, char * argv[])
{
// printf("Hello World!\n");
cout << " Hello, I'm here. " << endl;
// system("dir");
long handle; // 用于查找的句柄
struct _finddata_t fileinfo; // 文件信息的结构体
handle = _findfirst(to_search, & fileinfo); // 第一次查找
if ( - 1 == handle){
cout << " 操作失败,提前结束程序 " << endl;
system( " pause " );
return - 1 ;
}
// printf("%s\n",fileinfo.name); // 打印出找到的文件的文件名
printf( " ,%d\n " ,fileinfo.time_write); // 打印出找到的文件的文件名
while ( ! _findnext(handle, & fileinfo)) // 循环查找其他符合的文件,直到找不到其他的为止
{
if (fileinfo.attrib == _A_ARCH){
printf( " 存档, " );
} else if (fileinfo.attrib == _A_NORMAL){
printf( " 正常, " );
} else if (fileinfo.attrib == (_A_HIDDEN | _A_ARCH)){
printf( " 隐藏, " );
} else if (fileinfo.attrib == _A_RDONLY){
printf( " 只读, " );
} else if (fileinfo.attrib == _A_SUBDIR){
printf( " 文件夹, " );
} else if (fileinfo.attrib == _A_SYSTEM){
printf( " 系统, " );
}
printf( " %s, %d, %d\n " ,fileinfo.name,fileinfo.attrib,_A_HIDDEN | _A_ARCH);
}
_findclose(handle); // 别忘了关闭句柄
//
// *
// 删除指定的文件,只能删除空的文件夹
// char *removePath = "temp\\test";
// 删除文件夹
// int status = _rmdir(removePath);
// 删除文件
char * removePath = " ..\\temp\\test.txt " ;
int status = remove(removePath);
if (status == - 1 ){
printf( " 删除失败..\n " );
} else {
// 0表示删除成功
printf( " 删除成功..\n " );
}
// */
// 修改文件名
char * initPath = " ..\\temp\\c1.txt " ;
char * newPath = " ..\\temp\\c1_copy.txt " ;
status = rename(initPath, newPath);
if (status == - 1 ){
printf( " 改动失败..\n " );
} else {
printf( " 改动成功..\n " );
}
// 创建文件夹
char * newDir = " ..\\temp\\testA " ;
status = _mkdir(newDir);
if (status == - 1 ){
printf( " 创建失败..\n " );
} else {
printf( " 创建成功..\n " );
}
// system("dir temp\\testA");
system( " pause " );
return 0 ;
}
//
#include " stdafx.h "
#include < cstdlib >
#include < iostream >
#include < io.h >
#include < direct.h >
using namespace std;
const char * to_search = " ..\\temp\\*.* " ; // 查找当前文件夹下temp文件夹下的所有文件或文件夹
int main( int argc, char * argv[])
{
// printf("Hello World!\n");
cout << " Hello, I'm here. " << endl;
// system("dir");
long handle; // 用于查找的句柄
struct _finddata_t fileinfo; // 文件信息的结构体
handle = _findfirst(to_search, & fileinfo); // 第一次查找
if ( - 1 == handle){
cout << " 操作失败,提前结束程序 " << endl;
system( " pause " );
return - 1 ;
}
// printf("%s\n",fileinfo.name); // 打印出找到的文件的文件名
printf( " ,%d\n " ,fileinfo.time_write); // 打印出找到的文件的文件名
while ( ! _findnext(handle, & fileinfo)) // 循环查找其他符合的文件,直到找不到其他的为止
{
if (fileinfo.attrib == _A_ARCH){
printf( " 存档, " );
} else if (fileinfo.attrib == _A_NORMAL){
printf( " 正常, " );
} else if (fileinfo.attrib == (_A_HIDDEN | _A_ARCH)){
printf( " 隐藏, " );
} else if (fileinfo.attrib == _A_RDONLY){
printf( " 只读, " );
} else if (fileinfo.attrib == _A_SUBDIR){
printf( " 文件夹, " );
} else if (fileinfo.attrib == _A_SYSTEM){
printf( " 系统, " );
}
printf( " %s, %d, %d\n " ,fileinfo.name,fileinfo.attrib,_A_HIDDEN | _A_ARCH);
}
_findclose(handle); // 别忘了关闭句柄
//
// *
// 删除指定的文件,只能删除空的文件夹
// char *removePath = "temp\\test";
// 删除文件夹
// int status = _rmdir(removePath);
// 删除文件
char * removePath = " ..\\temp\\test.txt " ;
int status = remove(removePath);
if (status == - 1 ){
printf( " 删除失败..\n " );
} else {
// 0表示删除成功
printf( " 删除成功..\n " );
}
// */
// 修改文件名
char * initPath = " ..\\temp\\c1.txt " ;
char * newPath = " ..\\temp\\c1_copy.txt " ;
status = rename(initPath, newPath);
if (status == - 1 ){
printf( " 改动失败..\n " );
} else {
printf( " 改动成功..\n " );
}
// 创建文件夹
char * newDir = " ..\\temp\\testA " ;
status = _mkdir(newDir);
if (status == - 1 ){
printf( " 创建失败..\n " );
} else {
printf( " 创建成功..\n " );
}
// system("dir temp\\testA");
system( " pause " );
return 0 ;
}