Thread: Another CMD Line Batch File to C++ Question

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    8

    Another CMD Line Batch File to C++ Question

    I am trying to follow a working example of something I have done a couple of years ago:

    Code:
    #include <cstdlib> int main(void) { std::system("\"C:\\Program Files (x86)\\Runtime Software\\DriveImage XML\\dixml.exe\" /bc /tD:\\Backup\\DIXML %date:~4,2%-%date:~7,2%-%date:~10% /r- /s- /c2 /v"); return 0; }
    After making a working batch file:

    Code:
    forfiles.exe /p "C:\Users\TESTING\Desktop\Text Test" /s /m *.txt /d -153 /c "cmd /c del @path"
    I am getting a bunch of errors with the following:

    Code:
     #include<cstdlib>
    int main(void)
    {
    std::system("\"C:\\Windows\\System32\\forfiles.exe\" /p "\"C:\\Users\\TESTING\\Desktop\\Text Test\" /s /m *.txt /d -153 /c "\"cmd /c del @path\");
    return 0;
    }
    
    What am I doing wrong?

  2. #2
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Code:
    system("\"C:\\Windows\\System32\\forfiles.exe\" /p \"C:\\Users\\TESTING\\Desktop\\Text Test\" /s /m *.txt /d -153 /c \"cmd /c del @path\"");
    The syntax coloring in your post actually gives it away, you have some extraneous "s in the string. Try the one above, should work.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    8
    When the CMD window opens, I see the following:

    The filename directory name, or volume label syntax is incorrect.

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    8
    I just got it working by adding another "\

    BEFORE:

    Code:
     std::system("\"C:\\Windows\\System32\\forfiles.exe\" /p \"C:\\Users\\Longhair\\Desktop\\Text Test\" /s /m *.txt /d -153 /c \"cmd /c del @path\"");
    
    AFTER:

    Code:
     std::system("\"\"C:\\Windows\\System32\\forfiles.exe\" /p \"C:\\Users\\Longhair\\Desktop\\Text Test\" /s /m *.txt /d -153 /c \"cmd /c del @path\"");
    
    Thanks for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie Question: CMD Line Batch File to C++
    By Longhair in forum C++ Programming
    Replies: 8
    Last Post: 09-21-2011, 09:42 AM
  2. Batch file
    By HunterCS in forum Tech Board
    Replies: 4
    Last Post: 05-19-2007, 12:21 AM
  3. help me convert a batch file to C++...please
    By laar in forum Windows Programming
    Replies: 3
    Last Post: 01-20-2006, 02:24 AM
  4. Batch file or VisualBasic file to send to USB port
    By Rod McDevitt in forum Windows Programming
    Replies: 1
    Last Post: 03-28-2004, 03:09 AM
  5. Batch file?
    By Silentsharp in forum C++ Programming
    Replies: 1
    Last Post: 02-22-2002, 06:23 PM