I'm trying to create a batch file that will run Doug Cockford's JSMin against all the .js files in a directory. Here's what i've got:

我正在尝试创建一个批处理文件,该文件将针对目录中的所有.js文件运行Doug Cockford的JSMin。这是我得到的:

for /f %%a IN ('dir /b /s *.js') do jsmin <%%a >%%~da%%~pamin\%%~na.min%%~xa

The problem is that the angle brackets (<>) cause the batch file to interpret it as 0< and 1>. Event running just:

问题是尖括号(<>)导致批处理文件将其解释为0 <和1> 。活动正好:

jsmin <scripts\script.js >jsmin-stuff.js

in a batch file does the same thing. Escaping the angle brackets with ^ makes jsmin think that the angle brackets are part of the path.

在批处理文件中做同样的事情。使用^转义尖括号使得jsmin认为尖括号是路径的一部分。

Any ideas? What am I doing wrong?

有任何想法吗?我究竟做错了什么?

1 个解决方案

#1


First of all, you are using for /f for something where for alone is sufficient. Secondly, I don't recommend doing this recursively, as you are obviously placing the min-ified scripts into a subfolder of the same tree.

首先,你正在使用/ f来满足单独使用的东西。其次,我不建议递归地执行此操作,因为您显然将min-ified脚本放入同一树的子文件夹中。

for %x in (*.js) do jsmin <"%x" >"min\%~nx-min.js"

(from the command line, not from a batch) does what it should for me here. What you are seeing with 0< and 1> is actually correct, as 0 is the standard input stream and 1 the standard output stream, which you are both redirecting.

(从命令行,而不是从批处理)做我应该在这里做的事情。您看到的0 <和1> 实际上是正确的,因为0是标准输入流,1是标准输出流,您将重定向。

For doing this recursively the following line did the trick for me:

为了递归地执行此操作,以下行为我做了诀窍:

for /r %x in (*.js) do jsmin <"%x" >"%~dpx\min\%~nx-min.js"

ETA: Ok, I checked it, the dir method works in fact more reliable than using for /r. I apologize. From a batch file the following worked for me:

ETA:好的,我查了一下,dir方法实际上比使用for / r更可靠。我道歉。从批处理文件中,以下对我有用:

for /f "usebackq delims=" %%x in (`dir /s /b *.js`) do jsmin <"%%x" >"%%~dpx\min\%%~nx-min.js"

for /f always does tokenizing, usually only based on whitespace, though. But my profile folder already has whitespace in it, so better turn off tokenizing altogether.

for / f总是进行标记化,通常只基于空格。但我的个人资料文件夹中已经有空格,所以最好完全关闭标记。

更多相关文章

  1. 使用python api递归计算每个Dropbox文件夹大小
  2. 学习python的第十六天(迭代器,三元表达式,列表生成式,字典生成式,
  3. 绕脑的汉诺塔递归
  4. sqlserver 存储过程 递归查询分组+hierarchyid重建会员关系
  5. SQL Server 2005递归查询在数据中有循环,这是可能的吗?
  6. 如何在Java中递归解压缩文件?
  7. 二分法查找递归方式()
  8. Java递归实现算24

随机推荐

  1. C语言中switch语句的case后能否是一个关
  2. c语言中return的用法是什么?
  3. #include和#define是C语句吗?
  4. c语言中标识符不能与保留字同名吗?
  5. C语言中有且唯一的函数是什么
  6. C语言中取地址运算符是什么?
  7. 两分钟带你了解如何使用“strcpy()”函数
  8. putchar函数可以向终端输出一个字符么
  9. C语言怎么获取数组的长度
  10. C语言中求余运算符是什么?