Forum Discussion

mvandenberg2's avatar
Occasional Contributor
11 years ago

Jscript - Execute DOS command


I'm trying to execute a dos command in Jscript, but I keep getting "The system cannot find the file specified"

I'm sure it has something to do with qoutes. I've tried every combination I could think of, but I can't get it right.

I want to get the list of files in a directory and write it to a file. If there is a better way of doing it then I'll try that as well.

This is my code:

var command = "dir /b c:\ProgramData\testfolder1\testfolder2 >D:\Automation\Data\testdata\testfile.csv"



  • var command = "cmd /c dir /b c:\ProgramData\testfolder1\testfolder2 >D:\Automation\Data\testdata\testfile.csv"

1 Reply

  • karkadil's avatar
    Valued Contributor
    var command = "cmd /c dir /b c:\ProgramData\testfolder1\testfolder2 >D:\Automation\Data\testdata\testfile.csv"