如何写文件名 [英] how write file name

查看:187
本文介绍了如何写文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


我想知道这段代码是通过使用bool从存在下一个文件的目录进行目录扫描返回我的,它使用bool给我信号1的文件的存在.
我想写文件名如何

 CFileFind查找;
      CString path = " ;
      如果(path.Right( 1 )!= "  \\")
      路径+ = " ;
      路径+ = " ;
      BOOL找到= find.FindFile(path);
      同时(找到)
      {
      找到= find.FindNextFile();
       // 在这里,我需要文件名以及如何获取文件名
      如果(find.IsDots())
          继续;
      }


在这里

发现是bool,它会扫描目录并运行循环,直到有可用的文件

我想写文件名以及该怎么做,然后我必须再使用文件名

嗯,由于您使用的是CFileFind类的实例-查找",因此可以通过msdn CFileName对其进行解释"的成员函数.其中之一肯定会返回当前文件的名称. -是的! GetFileName()之类的东西.它是返回的CString.

您可以选择使用CString的向量保存匹配文件名的列表.

向量matchingFiles;
找到= find.FindNextFile();
//当获得与* .txt *匹配的cur文件名的CString时,保存它
matchingFiles.push_back(found.GetFileName());

是的,查克说了什么.


Hi All


i want to know that this code return me by doing directory scanning from directory that next file is present am using bool which give me presence of file with signal 1.
i want to write the names of files how

CFileFind find;
      CString path="C:\\TestFile";
      if(path.Right(1) != "\\")
      path += "\\";
      path += "*.txt*";
      BOOL found = find.FindFile(path);
      while (found)
      {
      found = find.FindNextFile();
       // here i need name of file also how to get the name of file
      if(find.IsDots())
          continue;
      }


here

found is bool it scan the directory and run the loop untill files are available

i want to write the names of files also how to do that then i have to use the name of file further

plz help

解决方案

Well, since you are using a an instance of the CFileFind class - ''find'', you can msdn CFileName for an explanation of it''s member functions. One of these will surely return the name of the current file. - it does! GetFileName(), of all things.. It''s a CString that is returned.

You may choose to use a vector of CStrings to hold the list of matching filenames.
i.e
vector matchingFiles;
found = find.FindNextFile();
// When you get a CString of the cur filename matching *.txt*, save it
matchingFiles.push_back(found.GetFileName());

And yeah, what Chuck said.


这篇关于如何写文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆