rejetto forum

macro mkdir with overwrite option

Mars · 3 · 3226

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
utilib.pas
Quote

function newMtime(fn:string; var previous:Tdatetime):boolean;
function dirCrossing(s:string):boolean;
function forceDirectory(path:string;overwrite:boolean=FALSE):boolean; //mod by mars
function moveToBin(fn:string; force:boolean=FALSE):boolean;
function uri2disk(url:string; root:Tfile=NIL):string;

......
implementation
....
function forceDirectory(path:string;overwrite:boolean=FALSE):boolean;  //mod by mars
var
  s: string;
begin
result:=TRUE;
path:=excludeTrailingPathDelimiter(path);
if path = '' then exit;
try
  if overwrite then movetobin(path,TRUE); //add by mars
except end;

if directoryExists(path) then exit;
s:=ExtractFilePath(path);
forceDirectory(s);
result:=CreateDir(path);
end; // forceDirectory

main.pas
Quote
   if name = 'mkdir' then
      spaceIf(forceDirectory(uri2diskMaybeFolder(p),isTrue(par('overwrite'))));   //mod by mars

with this update , you can overwrite an existing folder by moving it to the recycled bin , you lose nothing and if it is necessary you can recover it :)

usage: {.mkdir|foldername|overwrite=true.}
« Last Edit: September 04, 2009, 11:25:32 PM by Mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile
{.mkdir|foldername|overwrite=1.}
instead of
{.delete|foldername.}{.mkdir|foldername.}
i don't see a real improvement


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
The uniformity my dear friend, the uniformity...,
{.add folder|real or virtual| ....... | overwrite=1.}
{.mkdir| ................................. | overwrite=1.}
   
I LIKE THE UNIFORMITY , then you have to do what is necessary  ;)