System(); commands

This is a discussion on System(); commands within the C++ Programming forums, part of the General Programming Boards category; I am making a program to automatically hide / unhide files. My system command looks like this: system("ATTRIB +R +S ...

  1. #1
    Ryan
    Guest

    Unhappy System(); commands

    I am making a program to automatically hide / unhide files. My system command looks like this:
    system("ATTRIB +R +S +H", filename);

    where filename is the user's filepath input. Obviously it doesnt work, so I need to know how to get it to enter the variable. thanks in advance

  2. #2
    Ryan
    Guest
    I have updated it to work very well. I now have a new problem. Only 1 error. Looks devastating though :/ here:

    #include <process.h>
    #include <conio.h>
    #include <stdio.h>
    #include <iostream.h>
    #include <string.h>

    main()
    {
    char command [100];
    cin>>&command [100];

    command [100] = "ATTRIB +R +S +H %c", command [100];

    system(&command[100]);



    return 0;
    }



    the error is
    C:\MSDEV\Projects\l33t\l33t.cpp(12) : error C2446: '=' : no conversion from 'char [19]' to 'char' (new behavior; please see help)

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    16
    Alright, I think I have the answer to your question. When using the system() command, anything typed inside those parantheses and also in the quotation marks is EXACTLY what goes to the DOS prompt. So if you want to hide a file, put what you would put on the prompt inside the quotes. Here's the code you would want. I tested this and it worked perfectly.

    system("ATTRIB +R +S +H whatever.txt");

    Dump the comma, put the filename in quotes. But now I have a question... when I tested this code, I hid a couple of files and can't get them back... Do you know the command to unhide them? =)
    I tried ATTRIB -H and a couple other things... can't seem to get it back. I'm retarded. Thanks. Hope it helped you.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    what i would probably do is append the strings together first
    i'd use new to help create the proper string

    something like:
    Code:
    char * command;
    int length1 = strlen("ATTRIB +R +S +H ");
    int length2 = strlen(filename);
    command = new char [length1 + length2 + 1];
    strcpy(command,"ATTRIB +R +S +H ");
    strcat(command, filename);
    system(command);
    don't forget that you need a space after the last attrib
    Last edited by Syneris; 03-13-2002 at 07:35 PM.

  5. #5
    Ryan
    Guest
    ty, both of u

    nate: ATTRIB -R -S -H whatever.txt to unhide

  6. #6
    Ryan
    Guest
    Syneris :
    C:\MSDEV\Projects\l33t\l33t.cpp(11) : error C2664: 'strlen' : cannot convert parameter 1 from 'char' to 'const char *' (new behavior; please see help)
    C:\MSDEV\Projects\l33t\l33t.cpp(14) : error C2664: 'strcat' : cannot convert parameter 2 from 'char' to 'const char *' (new behavior; please see help)

  7. #7
    Ryan
    Guest
    NM i caught ur mistake (forgots &s) happy halloween!

  8. #8
    Ryan
    Guest
    Are you tyring to mkae me look stupid?

    command = new char [length1 + length2 + 1];

    what is wrong with this picture? yes, thats right, the +1, it added an ascii 1 character to everything i typed. had me baffled for a while but it should be like this

    command = new char [length1 + length2];

  9. #9
    ,mo ftbol!
    Join Date
    Dec 2001
    Posts
    2,136
    The plus one added an extra character for the null terminator.

    P.S. Files aren't really hidden in Windows. Just go to folder options and choose show hidden files and it will just have them shadowy(if it's a word) so you know they're hidden.

  10. #10
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    the +1 is there to make the new character array large enough to hold the null character (to terminate the string).

  11. #11
    Unregistered
    Guest
    i created a test program and tested syneris' code
    it worked perfect! see for yourself
    #include <iostream.h>
    #include <string.h>
    #include <stdlib.h>


    const int MAXFILENAME = 80;

    int main()
    {
    char filename[MAXFILENAME];
    cout << "Enter filename: ";
    cin.getline(filename, MAXFILENAME);
    char * command;
    int length1 = strlen("ATTRIB +R +S +H ");
    int length2 = strlen(filename);
    command = new char [length1 + length2 + 1];
    strcpy(command,"ATTRIB +R +S +H ");
    strcat(command, filename);
    system(command);
    cout << command << " Complete" << endl;
    return 0;
    }

  12. #12
    Registered User
    Join Date
    Feb 2002
    Posts
    16
    Unrelated to the actual code... but for golfinguy, i knew that they aren't hidden really in windows, however if you hide files in DOS with those attributes, they ARE hidden in windows, for real. Not just shadowy type thing. But thanks Ryan for helping me fix that...

  13. #13
    S剝nior Member
    Join Date
    Jan 2002
    Posts
    982
    >they ARE hidden in windows, for real

    No they're not, just disable the system file protection.

  14. #14
    Ryan
    Guest
    I have totally upgraded it to make it alot better hidden. I am getting trouble. I marked where i get the error.

    #include <iostream.h>
    #include <string.h>
    #include <stdlib.h>


    const int MAXFILENAME = 80;

    int main()
    {
    char filename[MAXFILENAME];
    while(filename != "C:\\")
    {
    cout << "\nEnter filename: ";
    cin.getline(filename, MAXFILENAME);
    char * command;
    int length3 = strlen("RENAME ");
    int length5 = strlen( "AfS.abC");
    int length1 = strlen("ATTRIB +R +S +H ");
    int length2 = strlen(filename);
    command = new char [length1 + length2 + 1];
    strcpy(command,"ATTRIB +R +S +H ");
    strcat(command, filename);
    system(command);
    command = new char [length3 + length2 + length5 + 1];
    strcpy(command,"rename "); // the error
    strcat(command, filename); //occurs
    strcpy(command, " C:\\AfS.abC"); //somewhere in these lines
    cout<< command;
    system("mkdir C:\\中么\");
    system("mkdir C:\\中么\中中\\");
    system("mkdir C:\\中么\中中\\中中么\");
    system("mkdir C:\\中么\中中\\中中么\中中中\\");
    system("mkdir C:\\中么\中中\\中中么\中中中\\ABcDEfGGASdFFdDFFfAF GSDFGVVFGDFGSFGGRFVFGGBFDSFDSB\\");
    system("move C:\\AfS.abC C:\\中么\中中\\中中么\中中中\\ABcDEfGGASdFFdDFFfAF GSDFGVVFGDFGSFGGRFVFGGBFDSFDSB");
    system("ATTRIB +R +S +H C:\\中么\中中\\中中么\中中中\\ABcDEfGGASdFFdDFFfAF GSDFGVVFGDFGSFGGRFVFGGBFDSFDSB");
    system("ATTRIB +R +S +H C:\\中么\中中\\中中么\中中中");
    system("ATTRIB +R +S +H C:\\中么\中中\\中中");
    system("ATTRIB +R +S +H C:\\中么\中中");
    system("ATTRIB +R +S +H C:\\中");
    system("ATTRIB +R +S +H C:\\中么\中中\\中中么\中中中\\ABcDEfGGASdFFdDFFfAF GSDFGVVFGDFGSFGGRFVFGGBFDSFDSB\\AfS.abC");
    cout<< command << " |||Complete||| ";
    }
    return 0;
    }

  15. #15
    ,mo ftbol!
    Join Date
    Dec 2001
    Posts
    2,136
    strcpy(command,"rename "); // puts rename in command
    strcat(command, filename); //adds filename to end
    strcpy(command, " C:\\AfS.abC"); //overwrites, not adding to end

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-30-2009, 01:25 AM
  2. running system commands??
    By killdragon in forum C++ Programming
    Replies: 13
    Last Post: 09-25-2004, 03:49 PM
  3. what can i type into msdn to bring up all the system commands
    By Shadow12345 in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2002, 06:58 PM
  4. Capturing system commands
    By manwhoonlyeats in forum C Programming
    Replies: 2
    Last Post: 12-07-2002, 07:38 PM
  5. system commands
    By mervin in forum C Programming
    Replies: 3
    Last Post: 02-03-2002, 09:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21