批量搜索文件夹

时间:2014-03-27 09:43:17

标签: batch-file batch-processing file-conversion

我正在尝试编写批处理文件。它在文件夹中查找特定文件,使用它们的路径并使用它们来调用java脚本:例如:我在桌面上有一个文件夹cbacklog,其中包含 *。xls 文件,我有一个 converter.js java脚本。我想查看 cbacklog 如果它有excell文件,我将采用此文件路径并调用 converter.js 转换器将转换此文件。然后批处理文件将移动到下一个excell文件...采取它的拍子并将其用于convert.js

var fso = new ActiveXObject("Scripting.FileSystemObject");
var xls03Path = WScript.Arguments(0);
xls03Path = fso.GetAbsolutePathName(xls03Path);

var xls95Path = xls03Path.replace("cbacklog", "dbacklog");

xls95Path  =xls95Path.replace(/\.xls[^.]*$/, ".xls");


var objExcel = null;



try
{
    WScript.Echo("Saving '" + xls03Path + "' as '" + xls95Path + "'...");

   objExcel = new ActiveXObject("Excel.Application");

    objExcel.Visible = false;


    var objExcl = objExcel.Workbooks.Open(xls03Path);

    var wdFormatxls = 39;
    objExcl.SaveAs(xls95Path, wdFormatxls);

    objExcl.Close();

    fso.MoveFile(xls03Path,"C:\\Users\\cguneyel\\Desktop\\cbacklog\\processed\\");

}
finally
{
    if (objExcl != null)
    {
        objExcl.Quit();
    }
}

1 个答案:

答案 0 :(得分:0)

for %%a in ("c:\somewhere\cbacklog\*.xls") do cscript converter.js "%%~fa"

对于文件夹中的每个xls文件,使用文件的完整路径作为参数调用脚本