-
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
-
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)
-
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.
-
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
-
ty, both of u
nate: ATTRIB -R -S -H whatever.txt to unhide
-
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)
-
NM i caught ur mistake (forgots &s) happy halloween!
-
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];
-
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.
-
the +1 is there to make the new character array large enough to hold the null character (to terminate the string).
-
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;
}
-
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...
-
>they ARE hidden in windows, for real
No they're not, just disable the system file protection.
-
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;
}
-
strcpy(command,"rename "); // puts rename in command
strcat(command, filename); //adds filename to end
strcpy(command, " C:\\AfS.abC"); //overwrites, not adding to end