Forum Discussion

mvandenberg2's avatar
mvandenberg2
Occasional Contributor
11 years ago
Solved

Jscript - Execute DOS command

Hi,



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"



Sys.OleObject("Wscript.Shell").Exec(command)



 


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

1 Reply

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