-1

I am trying to write a batch file . which looks in a folder for specific files, takes their path and uses them for calling a java script: for example: i have a folder cbacklog in desktop which include *.xls file and i have a converter.js java script. i want to look in cbacklog if it has excell files , i will take this file path and call converter.js converter will convert this file. then batch file will move to next excell file... take its pats and uses it for 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();
    }
}
user32
  • 29
  • 1
  • 2
  • 6

1 Answers1

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

for each xls file in folder call the script with the full path to file as argument

MC ND
  • 69,615
  • 8
  • 84
  • 126
  • to call my javascript i use this: cscript.exe //nologo //E:jscript C:\Users\user\Desktop\cbacklog\converter.js C:\Users\user\Desktop\cbacklog\test.xls – user32 Mar 27 '14 at 10:01
  • @user32, if you are running it from command line, replace `%%` with `%`. The command, as it is written, is for batch file which needs percent signs escaped. What problem do you have with with the way you call your script? The `//nologo` is just to not show "logo", the `//E:` is not needed in this case as it is infered from the script extension and the full path to the .xls file is being passed as argument. Where is the problem? – MC ND Mar 27 '14 at 10:22