当搜索字符串包含减号时,FINDSTR失败

时间:2017-09-15 10:31:10

标签: batch-file command-line windows-8.1

我会递归地浏览所有JS文件并缩小它们。但是我必须保留一些JS文件。

我使用dirfindstrfor /f %i in ('dir /b /a-d /s "D:\update" ^| findstr /liv "\admin" ^| findstr /ile ".js" ^| findstr /vile "-min.js" ^| findstr /vile ".min.js"') do echo %i 的组合获得了很多成功。但是当我想忽略已经缩小的文件(以“-min.js”结尾的文件)时,FINDSTR命令就崩溃了。

这是我用过的命令:

FINDSTR: /. ignored
FINDSTR: /j ignored
FINDSTR: Bad command line
FINDSTR: Write error
FINDSTR: Write error
FINDSTR: Write error
FINDSTR: Write error

出现以下错误:

findstr /vile "-min.js"

问题肯定是使用[ { "id": 19, "subSpecialtyId": 1, "institutionAccreditationApplicationId": 13, "subSpecialtyName": "Chromatography", "exams": [ { "id": 1001, "name": "Part 1", "departmentId": 0, "designation": null, "index": 4, "statuses": [ { "id": 1, "name": "Full", "departmentId": 0, "designation": null }, { "id": 2, "name": "Partial", "departmentId": 0, "designation": null }, { "id": 3, "name": "Denied", "departmentId": 0, "designation": null }, { "id": 1002, "name": "Full for Part 1", "departmentId": 0, "designation": null } ] }, { "id": 1002, "name": "Part II", "departmentId": 0, "designation": null, "index": 5, "statuses": [ { "id": 1, "name": "Full", "departmentId": 0, "designation": null }, { "id": 2, "name": "Partial", "departmentId": 0, "designation": null }, { "id": 3, "name": "Denied", "departmentId": 0, "designation": null }, { "id": 1002, "name": "Full for Part 1", "departmentId": 0, "designation": null } ] } ] }, { "id": 20, "subSpecialtyId": 4, "institutionAccreditationApplicationId": 13, "subSpecialtyName": "Sub Specialty F", "exams": [ { "id": 1001, "name": "Part 1", "departmentId": 0, "designation": null, "index": 4, "statuses": [ { "id": 1, "name": "Full", "departmentId": 0, "designation": null }, { "id": 2, "name": "Partial", "departmentId": 0, "designation": null }, { "id": 3, "name": "Denied", "departmentId": 0, "designation": null }, { "id": 1002, "name": "Full for Part 1", "departmentId": 0, "designation": null } ] }, { "id": 1002, "name": "Part II", "departmentId": 0, "designation": null, "index": 5, "statuses": [ { "id": 1, "name": "Full", "departmentId": 0, "designation": null }, { "id": 2, "name": "Partial", "departmentId": 0, "designation": null }, { "id": 3, "name": "Denied", "departmentId": 0, "designation": null }, { "id": 1002, "name": "Full for Part 1", "departmentId": 0, "designation": null } ] } ] } ] 子句但是我不知道为什么连字符会导致问题,因为我使用的是/ l(文字)标志。

1 个答案:

答案 0 :(得分:3)

处理class(gd) [1] "grouped_df" "tbl_df" "tbl" "data.frame" class(meansummpas) [1] "data.frame" 可执行文件参数的C运行时遵循一组规则。其中一条规则是使用双引号来保护单独参数中的空格/特殊字符,但是,一旦命令行被标记化并且标识了参数,就会在将单独的参数传递给主代码之前删除引号。

这意味着这个命令

findstr

将在可执行文件中处理为

findstr /vile "-min.js"

,并且,argv[0] = findstr argv[1] = /vile argv[2] = -min.js 接受参数分组(如findstr中所述),但它也允许以/vile/开头的参数,-接受-m-i-n次切换(全部有效),但会忽略-s-.(未知)。

命令行不好,因为在参数中找不到搜索字符串。

记录在案的(-j)解决方案是使用findstr /?语法

/c:"stringToMatch"

或者您可以使用转义字符,因此findstr /vile /c:"-min.js" 不会作为选项参数初始字符处理

-