Executing dir command


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Executing dir command

  1. #1
    Dasensa Guest

    Executing dir command


    Hi, I need your help.
    I want to save filenames in a directory to a text file using dir command
    (e.g. "dir *.* >> result.txt").
    I tried it, but it only displayed command prompt window.
    Here is the code:

    -------
    System.Diagnostics.Process search = new Process();
    search.StartInfo.FileName = "E:\\WINDOWS\\system32\\cmd.exe";
    search.StartInfo.Arguments = "dir *.* >> result.txt";
    search.StartInfo.UseShellExecute = true;
    search.Start();
    -------

    Do I miss something?
    Thanks for your help.

    = Dasensa =


  2. #2
    Boris Karadjov Guest

    Re: Executing dir command

    Use

    search.StartInfo.Arguments = "/C dir *.* >> result.txt";

    also consider replacing the hard-coded path to cmd.exe with Environment.SystemDirectory.
    --
    Boris Karadjov
    Brainbench MVP for Visual C++
    http://www.brainbench.com


    "Dasensa" <dasensa@softhome.net> wrote in message news:3faf41ae$1@devx7.web.devx.com...
    >
    > Hi, I need your help.
    > I want to save filenames in a directory to a text file using dir command
    > (e.g. "dir *.* >> result.txt").
    > I tried it, but it only displayed command prompt window.
    > Here is the code:
    >
    > -------
    > System.Diagnostics.Process search = new Process();
    > search.StartInfo.FileName = "E:\\WINDOWS\\system32\\cmd.exe";
    > search.StartInfo.Arguments = "dir *.* >> result.txt";
    > search.StartInfo.UseShellExecute = true;
    > search.Start();
    > -------
    >
    > Do I miss something?
    > Thanks for your help.
    >
    > = Dasensa =
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center