Hie there i am having a small problem which needs assistance My program Removes the directory from the first argument. If that directory is not empty then delete files from it using next arguments. Code: #include "stdafx.h" #include <windows.h> int _tmain(int argc, _TCHAR* argv[]) { int i=3; while(i<=argc) if(DeleteFile(argv[i]) != 0) printf("\n%S file successfully deleted!\n", argv[i]); else printf("\n%S file deletion failed!\n", argv[i]); i++; // Delete the directory... if(RemoveDirectory != 0) printf("\n%S directory successfully deleted.\n",argv[i] ); else printf("\n%S directory deletion failed.\n", argv[i]); return 0; } The build is successful.But it does not debug. Nissi
Code: while(...) { if(DeleteFile(...) printf(...) else printf(...) ++i; } you should probably enclose that in curely braces the command line may mangle spaces. if you've got spaces in file/path names, try quoting around them on the command line. "some path"\"some file".ext If it's not a typo, RemoveDirectory takes a LPCTSTR as the path for an argument. Have you tried calling GetLastError() to see what, if any, errors there may be after the API calls?
Thanks hobbyist it worked i added a few more arguments #include "stdafx.h" #include <windows.h> int _tmain(int argc, _TCHAR* argv[]) { if (argc < 2) { fprintf (stderr, "Usage: Lab3_3 directory_2_delete fil1_2_del fil2_2_del ...filN_2_del \n"); return 1; } int i=3; TCHAR str[256]; while(i<=argc) { _tcscpy( str, argv[1] ); _tcscat( str, TEXT("\\") ); _tcscat( str, argv[i-1] ); if(DeleteFile(argv[i-1]) != 0) printf("\n%S file successfully deleted!\n", argv); else printf("\n%S file deletion failed!\n", argv); i++; } // Delete the directory... if(RemoveDirectory(argv[1]) != 0) printf("\n%S directory successfully deleted.\n",argv ); else printf("\n%S directory deletion failed.\n", argv); return 0; } My other question is how do i use it in cmd prompt .May i please have an example.By the way i have Total commander i created the file but do not exactly know how what to put in cmd
I'm not familair with total commander, but using XP, for example, if you clicked on the start button, clicked "run" and typed "cmd" in the dialog box you'd get the command prompt that looked something like . Code: c:\>documents and settings\current_user> from there, you'd type in the full path to your executable along with any command line arguments. Code: executable_drive:\executable_path\executable_name command_line_arguments as an example, if your executable is in the root folder of c:\, and you created a folder in the root of c:\ named lab3_3 with your files, then using your program's instructions, you'd type something like below Code: c:\documents and settings\current_user>c:\lab3_3 c:\lab3_3 fil1_2_delete fil2_2_delete ... just to make sure your paths are being formed correctly, you might first want to output the generated paths before actually trying to delete the files and folder. One other thing you might want to add is a call to getchar at the end of your program's code but before return 0. That would keep the window open so that you could see the output in case you ran it directly without opening the cmd window. Code: code while(getchar() != '\n'){} return 0; hope that helps