#include <windows.h>
#include <stdio.h>
#include <malloc.h>
-#include <tchar.h>
-#include <wchar.h>
+#include <tchar.h>
+#include <wchar.h>
#include <stdio.h>
#define BUFSIZE MAX_PATH
// Find the first file in the directory.
hFind = FindFirstFile(DirSpec, &FindFileData);
- if (hFind == INVALID_HANDLE_VALUE)
+ if (hFind == INVALID_HANDLE_VALUE)
{
- _tprintf (TEXT("Invalid file handle. Error is %u.\n"),
+ _tprintf (TEXT("Invalid file handle. Error is %u.\n"),
GetLastError());
retval = (-1);
- }
- else
+ }
+ else
{
// NOTE:
// Be very sure to not include '..' in the results, it will
listing.push_back(node);
// List all the other files in the directory.
- while (FindNextFile(hFind, &FindFileData) != 0)
+ while (FindNextFile(hFind, &FindFileData) != 0)
{
DirListNode node;
node.name = FindFileData.cFileName;
dwError = GetLastError();
FindClose(hFind);
- if (dwError != ERROR_NO_MORE_FILES)
+ if (dwError != ERROR_NO_MORE_FILES)
{
- _tprintf (TEXT("FindNextFile error. Error is %u.\n"),
+ _tprintf (TEXT("FindNextFile error. Error is %u.\n"),
dwError);
retval = (-1);
goto Cleanup;
//for(unsigned int i=0; i<listing.size(); i++){
// std::cout<<listing[i].name<<(listing[i].dir?" (dir)":" (file)")<<std::endl;
//}
-
+
return listing;
}
std::cerr<<"Removing \""<<path<<"\""<<std::endl;
//return false;
-
+
// This silly function needs a double-null terminated string...
// Well, we'll just make sure it has at least two, then.
path += "\0\0";
sfo.pFrom = path.c_str();
sfo.pTo = NULL;
sfo.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;
-
+
int r = SHFileOperation(&sfo);
if(r != 0)
#else // POSIX
+#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
/*
Execute the 'rm' command directly, by fork() and execve()
*/
-
+
std::cerr<<"Removing \""<<path<<"\""<<std::endl;
//return false;
-
+
pid_t child_pid = fork();
if(child_pid == 0)
std::cerr<<"Executing '"<<argv[0]<<"' '"<<argv[1]<<"' '"
<<argv[2]<<"'"<<std::endl;
-
+
execv(argv[0], argv);
-
+
// Execv shouldn't return. Failed.
_exit(1);
}