c/c++文件系统操作[vc.6.0]

//  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 ;
}

 

转载于:https://www.cnblogs.com/vilyLei/articles/1875530.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值