setAttributes Issue.

vino.B bheeman.vino at hotmail.com
Sun Jul 15 10:07:49 UTC 2018


Hi All,

  Request your help, can some one find what is the issue with the 
below code, as this is throwing the error "Access is denied". as 
the below code is supposed to to remove the read-only permission 
if set.


Code:
import std.algorithm;
import std.array;
import std.container.array;
import std.datetime.systime;
import std.file;
import std.stdio;
import std.typecons;

auto coAgedDirClean (string FFs) {
	auto dFiles = Array!(Tuple!(string, 
SysTime))(dirEntries(join([`\\?\`, FFs]), 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)));
     foreach(d; dFiles) {
         auto sDir  = Array!string (dirEntries(d[0], 
SpanMode.depth).filter!(a => a.isDir && !a.isSymlink).map!(a => 
(a.name)));
         foreach(DirEntry sd; sDir) {
             import core.sys.windows.windows;
             if ((sd.attributes & FILE_ATTRIBUTE_READONLY) != 0) { 
setAttributes(sd, sd.attributes & ~FILE_ATTRIBUTE_READONLY); }
             rmdirRecurse(sd);
		}}	
         dFiles.each!(f => rmdirRecurse(f[0]));
         return dFiles;
}

void main () {
string FFs = "C:\\Temp\\SAPNAS1\\BACKUP1";
writeln(coAgedDirClean(FFs)[]);
}

From,
Vino.B


More information about the Digitalmars-d-learn mailing list