Re: Calling Windows Command

2018-03-22 Thread rumbu via Digitalmars-d-learn

On Wednesday, 21 March 2018 at 18:50:38 UTC, Vino wrote:

Hi All,

 Request your help in calling the windows command to delete all 
file and folders recursively as the D function rmdirRecurse 
does not delete file in the permission of the file is readonly 
in windows 2008 R2


import std.process: execute;
import std.array: empty;
auto RemoveDir () (
auto dFiles = "C:\\Temp\Test1";
auto Step = "run";
if (Step == "run" && !dFiles.empty) {
version(Windows)
 {
  foreach(d; dFiles) {
  execute(["rmdir.exe","-command", "/S /Q", `~d~`]); } } } 
return dFiles;

)

void main () {
writeln(RemoveDir);
}

From,
Vino.N


It is faster if you use SHFileOperationW directly on Windows (and 
also it will ignore readonly attributes):


https://msdn.microsoft.com/en-us/library/windows/desktop/bb762164(v=vs.85).aspx


//not tested
void winrmdir(string path)
{
import core.sys.windows.shellapi;
import std.exception : enforce;
import std.file: FileException;
import std.utf: toUTF16;

auto shpath = (path ~ "\0\0").toUTF16();
SHFILEOPSTRUCTW s;
s.wFunc = FO_DELETE;
s.pFrom = shpath.ptr;
s.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
enforce!FileException(SHFileOperationW() == 0 && 
!s.fAnyOperationsAborted);

}




Calling Windows Command

2018-03-21 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help in calling the windows command to delete all 
file and folders recursively as the D function rmdirRecurse does 
not delete file in the permission of the file is readonly in 
windows 2008 R2


import std.process: execute;
import std.array: empty;
auto RemoveDir () (
auto dFiles = "C:\\Temp\Test1";
auto Step = "run";
if (Step == "run" && !dFiles.empty) {
version(Windows)
 {
  foreach(d; dFiles) {
  execute(["rmdir.exe","-command", "/S /Q", `~d~`]); } } } 
return dFiles;

)

void main () {
writeln(RemoveDir);
}

From,
Vino.N