首页 \ 问答 \ 在文件夹中的txt文件列表中搜索“关键字”,如果找到“关键字”(批量脚本),则将txt文件移动到另一个文件夹(Search “keyword” in a list of txt file in a folder and move txt file to another folder if “keyword” is found (batch scripting))

在文件夹中的txt文件列表中搜索“关键字”,如果找到“关键字”(批量脚本),则将txt文件移动到另一个文件夹(Search “keyword” in a list of txt file in a folder and move txt file to another folder if “keyword” is found (batch scripting))

以下是我的伪代码

For loop in a folder where contains a list of txt files
if (keyword is found in the txt file) && (keyword2 is found in the txt file) 
move the txt file to another folder 
log the current txt file name to temp file

关键字和关键字2不在同一行

如何编写批处理脚本?


Below is my pseudocode

For loop in a folder where contains a list of txt files
if (keyword is found in the txt file) && (keyword2 is found in the txt file) 
move the txt file to another folder 
log the current txt file name to temp file

keyword and keyword2 are not in the same line

How to write as batch script?


原文:https://stackoverflow.com/questions/43222710
更新时间:2022-03-05 17:03

最满意答案

strlen()用于C const char*字符串。 要获取字符串s的长度,请使用s.size()s.length() 。 如果要从string获取C string ,请使用s.c_str()

虽然C ++ 看起来 const char*string是可以互换的,但只有在将const char*转换为string时才会采用一种方式。

你没有理由想要使用strlenstrlen最有可能用循环定义,它永远不会像size() ,而大多数只是string类的长度属性的getter。 在调用没有C ++替代方法的C函数时,只将string转换为C字符串。


strlen() is for C const char* strings. To get the length of a string s, use s.size() or s.length(). If you want to get a C string from a string, use s.c_str().

Although C++ makes it seem that const char* and string are interchangeable, that only goes one way when converting const char* to string.

There is no reason why you would want to use strlen either. strlen is most likely defined with a loop, which will never be as efficiant as size(), which is most likley just a getter for a length property of the string class. Only convert string to C strings when calling C functions for which there is not a C++ alternative.

相关问答

更多
  • 为了安全起见,你不要破坏东西(例如,当这些字符串在你的代码中被更改或更进一步),或者你的程序崩溃(例如,如果返回的字符串是字面值,例如"hello I'm a literal string"你开始编辑它),复制返回的字符串。 你可以为此使用strdup() ,但是请阅读小字体 。 或者,如果您的平台上没有您自己的版本,那么您当然可以创建自己的版本。 问题依然存在:为什么你需要一个char* ,你不能改变你的代码,以便它可以与const char*吗? To be safe you don't break s ...
  • 这几乎可以肯定,因为您的二进制数据包含零值字节。 这些与null-terminators相同,其功能类似于strlen用于确定字符串的结尾。 可以说任意二进制数据不应被视为字符串。 所以请改用std::vector ,不要使用像strlen这样的函数。 This is almost certainly because your binary data contains zero-valued bytes. These are identical to null-terminators, whic ...
  • 如果您只想将std::string传递给需要const char*的函数即可使用 std::string str; const char * c = str.c_str(); 如果你想得到一个可写的副本,像char * ,你可以这样做: std::string str; char * writable = new char[str.size() + 1]; std::copy(str.begin(), str.end(), writable); writable[str.size()] = '\0'; / ...
  • strncpy(file_input, line.c_str(), 6); 但是,为什么要首先使用固定长度的缓冲区file_input ? 将它构建为一个新的std::string会比较安全,该std::string包含行中的前五个字符: std::string file_input(line, 0, 5); strncpy(file_input, line.c_str(), 6); But why would you want the fixed-length buffer file_input i ...
  • char * const *确实表示指向chars的常量指针的指针。 在该问题的代码中执行此强制转换的原因如下: p1和p2是指向常量位置的(非常量)指针。 我们假设这个位置的类型是const T 现在我们要将p1和p2为真实类型。 我们知道数组的每个元素都是char * ,因此T = char * 。 那就是const T是一个指向char的常量指针,它被写成char * const 。 由于p1和p2是指向数组元素的指针,因此它们的类型为const T * ,即char * const * 。 由于函数 ...
  • 我不确定这是否是导致错误的原因,但是atoi将其参数作为参数而不是char,而是指向一个参数。 所以代替atoi(temp [0]) 尝试这个 atoi(&temp[0]) 因为那是一个指针。 I'm not sure if this is what is causing the error, but atoi takes as its parameter not a char, but the pointer to one. So instead of atoi(temp[0]) try this at ...
  • strlen()用于C const char*字符串。 要获取字符串s的长度,请使用s.size()或s.length() 。 如果要从string获取C string ,请使用s.c_str() 。 虽然C ++ 看起来 const char*和string是可以互换的,但只有在将const char*转换为string时才会采用一种方式。 你没有理由想要使用strlen 。 strlen最有可能用循环定义,它永远不会像size() ,而大多数只是string类的长度属性的getter。 在调用没有C + ...
  • 您应该能够将String直接传递给期望const char *的C函数,并且它将自动转换为以null结尾的UTF-8字符串: let string = "string" let node = artnet_new(string, 1) 请参阅与C API交互以获取更多信息。 这里是相关的摘录: 当一个函数被声明为采用UnsafePointer参数时,它可以接受以下任何一种: 字符串值,如果类型是Int8或UInt8。 该字符串将在缓冲区中自动转换为UTF8,并将指向该缓冲区的指针传递给该函数。 Not s ...
  • const char *是通过在std :: string上调用.c_str()获得的。 您的程序很可能具有未定义的行为 ,因为您返回一个指向从函数myCFunctionReturningConstCharPtr()返回时取消分配的字符数组的指针。 实际上,你返回的const char*指向一个由本地std::string对象封装的字符数组; std::string对象的析构函数释放该数组,并在本地对象超出范围时调用析构函数,即从函数返回时。 稍后尝试取消引用您收到的指针会导致未定义行为,这意味着任何事情都 ...
  • 当您使用MFC并假设UNICODE构建(或者您不会有此错误!)时,最简单的方法可能是直接实例化wchar_t兼容的CString : CStringW szWide(getText()); AfxMessageBox(szWide); As you're using MFC and assuming a UNICODE build (or you wouldn't have this error!), probably the simplest way is to instantiate a wchar_ ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)