We know that C ++ has very powerful functions and is suitable for compiling system software. Using it, we can easily solve some difficult problems that we often encounter. For example, copy an implicit or system attribute file, especially an implicit file on a CD, or change the subdirectory name in any DOS version or windows.
Use a directory name with spaces in any DOS version. These problems are often hard to work with by operating systems or commonly used tool software. We can use the powerful functions of the C ++ language to compile some small programs and solve these problems smoothly.
1. Copy files with implicit or system attributes
The Copy Command provided by the operating system cannot copy files with implicit or system attributes, because the system prompts "File not found" during the copy process ". The following small program can solve this problem.
- // Copyfile. c
- # Include $ # @ 60; stdio. h $ # @ 62;
- # Include $ # @ 60; stdlib. h $ # @ 62;
- Main (int argc, char * argv [])
- {If (argc $ # @ 60; 3)
- {
- Printf ("\ n usage: COPYFILE
- $ # @ 60; source file name $ # @ 62; $ # @ 60; target file name $ # @ 62; \ n ");
- Exit (1 );
- }
- Copy (argv [1], argv [2]);
- }
-
- Copy (char * file1, char * file2)
- {
- Char ch;
- FILE * fp1, * fp2;
-
- If ((Fp1=Fopen(File1, "rb") = NULL)
- {
- Printf ("\ nCant open file % s", file1 );
- Fclose (fp1 );
- Return;
- }
- If ((Fp2=Fopen(File2, "wb") = NULL)
- {
- Printf ("\ nCant open file % s", file2 );
- Fclose (fp1 );
- Return;
- }
- Ch=Fgetc(Fp1 );
- While (! Feof (fp1 ))
- {
- Fputc (ch, fp2 );
- Ch=Fgetc(Fp1 );
- }
- Fclose (fp1 );
- Fclose (fp2 );
- Return;
- }
2. Change the subdirectory name in any DOS version or windows
DOS only provides programs for changing the sub-register name in version 6.x. Changing the directory name in windows is complicated. The following applet can easily change the name of any level-1 subdirectory, and can also be used to change the file name.
- // Copyfile. c
- # Include $ # @ 60; stdio. h $ # @ 62;
- # Include $ # @ 60; stdlib. h $ # @ 62;
- Main (int argc, char * argv [])
- {If (argc $ # @ 60; 3)
- {
- Printf ("\ n usage: COPYFILE
- $ # @ 60; source file name $ # @ 62; $ # @ 60; target file name $ # @ 62; \ n ");
- Exit (1 );
- }
- Copy (argv [1], argv [2]);
- }
-
- Copy (char * file1, char * file2)
- {
- Char ch;
- FILE * fp1, * fp2;
-
- If ((Fp1=Fopen(File1, "rb") = NULL)
- {
- Printf ("\ nCant open file % s", file1 );
- Fclose (fp1 );
- Return;
- }
- If ((Fp2=Fopen(File2, "wb") = NULL)
- {
- Printf ("\ nCant open file % s", file2 );
- Fclose (fp1 );
- Return;
- }
- Ch=Fgetc(Fp1 );
- While (! Feof (fp1 ))
- {
- Fputc (ch, fp2 );
- Ch=Fgetc(Fp1 );
- }
- Fclose (fp1 );
- Fclose (fp2 );
- Return;
- }
3. Use the directory name with spaces
The system uses spaces to differentiate the parameters of input DOS commands. Similarly, DOS commands such as MD, CD, and RD cannot use directory names containing spaces. However, when the CHKDSK command is used to check the disk, no error message is provided for the subdirectory name containing spaces. This indicates that the directory names containing spaces in DOS are valid. Because DOS commands cannot use directory names containing spaces, they can be encrypted. The following program describes how to use the C ++ language to create, enter, and delete subdirectories containing spaces.
- // Copyfile. c
- # Include $ # @ 60; stdio. h $ # @ 62;
- # Include $ # @ 60; stdlib. h $ # @ 62;
- Main (int argc, char * argv [])
- {If (argc $ # @ 60; 3)
- {
- Printf ("\ n usage: COPYFILE
- $ # @ 60; source file name $ # @ 62; $ # @ 60; target file name $ # @ 62; \ n ");
- Exit (1 );
- }
- Copy (argv [1], argv [2]);
- }
-
- Copy (char * file1, char * file2)
- {
- Char ch;
- FILE * fp1, * fp2;
-
- If ((Fp1=Fopen(File1, "rb") = NULL)
- {
- Printf ("\ nCant open file % s", file1 );
- Fclose (fp1 );
- Return;
- }
- If ((Fp2=Fopen(File2, "wb") = NULL)
- {
- Printf ("\ nCant open file % s", file2 );
- Fclose (fp1 );
- Return;
- }
- Ch=Fgetc(Fp1 );
- While (! Feof (fp1 ))
- {
- Fputc (ch, fp2 );
- Ch=Fgetc(Fp1 );
- }
- Fclose (fp1 );
- Fclose (fp2 );
- Return;
- }
- How to Write C ++ project development and project plan correctly
- Summary Notes on learning and exploring C ++ library functions
- In-depth demonstration of high security of C ++
- Describes in detail how to accurately Write C ++ languages.
- In-depth demonstration of high security of C ++