Solved

Creating a new folder

Posted on 2003-11-17
10
278 Views
Last Modified: 2010-04-05
I Have an application that creates a file with some information in it. Then it imports the information to it. I want that it Creates a new Folder, and the folder´s name will be the current date. Then cuts the files and copy it to the folder created.
0
Comment
Question by:Fredy992
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 3

Expert Comment

by:JDuncan
ID: 9763269
Look up ForceDirectories(DateToStr(date));

0
 

Author Comment

by:Fredy992
ID: 9763300
I want the routine to: Create a new Folder, and the folder´s name will be the current date. Then cut all of the files from a specific folder and copy it to the folder created.

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9763357
as alternative to JDuncon:
  createDirectory('Path\NameHere',nil);


>cut all of the files from a specific folder and copy it to the folder created.

from my paq:

uses shellapi;

procedure TForm1.Button1Click(Sender: TObject);
var I : Integer;
    opInfo : _SHFILEOPSTRUCT;
begin
  opInfo.pFrom := 'd:\TmpFolder';  //SourceFolder
  opInfo.pTo   := 'Path\NameHere';  //DestinationFolder
  opInfo.wFunc := FO_MOVE;  //Move it
  opInfo.fFlags := FOF_NOCONFIRMATION  or //no confirmation
                   FOF_NOCONFIRMMKDIR or
 //no confirmation                  FOF_RENAMEONCOLLISION or //rename if dest exist
                   FOF_SIMPLEPROGRESS;  //show a progress
  opInfo.hNameMappings := nil;  // no mappings
  opInfo.fAnyOperationsAborted := False; //obsolete
  opInfo.lpszProgressTitle := 'Moving . . .';  //foo simpleprogressdisplay
  opInfo.Wnd := self.handle;  //the parent of the progressdisplay
  SHFileOperation(opInfo);  //do it
end;

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9763361
typo
JDuncon -> JDuncan (sorry)
0
 
LVL 8

Assisted Solution

by:gmayo
gmayo earned 62 total points
ID: 9763688
I do a similar thing already. Every time it saves, it stores the old files in a dated directory:
{--------------------------------------------------------------------------------------------------}
function SaveData(basename : string; progressproc : TProgressProcedure) : boolean;
var
      f : TextFile;
      i : integer;
      t : TFile;
      s : string;
begin
      //if not FileExists(basename) then MkDir(basename);
      Result := true;
      i := 0;
      if Assigned(progressproc) then progressproc(0.0);

      s := basename + '\' + FormatDateTime('yyyy-mm-dd hh-nn-ss', Now);
      MkDir(s);

      while (Result = true) and (i < FileList.Count) do begin
            t := TFile(FileList.Objects[i]);

            if t.Save then begin
                  if t.ReadOnly then begin
        CopyFile(PChar(MakeFilename(basename, t.Name)), PChar(s + '\' + basename + '.' + t.Name), false)
                  end
                  else
                  begin
        RenameFile(MakeFilename(basename, t.Name), s + '\' + basename + '.' + t.Name);
        try
          AssignFile(f, MakeFilename(basename, t.Name));
          Rewrite(f);
          Result := t.SaveToFile(f);
        except
          Result := false;
        end;

        CloseFile(f);
                  end;
      if Assigned(progressproc) then progressproc((i + 1) / FileList.Count);

            end;
            Inc(i);
      end;
      if Assigned(progressproc) then progressproc(1.0);

end;
{--------------------------------------------------------------------------------------------------}

If there is too much in there, let me know and I will cut it down to what you need.

Geoff M.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Accepted Solution

by:
calinutz earned 63 total points
ID: 9763902
To create de folder is a very simple task:

var
 d,m,y:word;
 newdir:string;
begin
decodedate(now,y,m,d);
newdir:=IntToStr(d)+'_'+IntToStr(m)+'_'+IntToStr(y);
CreateDir('C:\'+newdir);
...

then to move the files from your temporary dir you should make a procedure. There is no direct way... like

Copy c:\temp\*.* to c:\NewDir\

But you can make a preocedure that does that very easily. If you want I can make you one and send it to your email...
Cheers
0
 

Author Comment

by:Fredy992
ID: 9765430
I made the following: And it worked. Does anyone see something wrong in it ?

procedure TfrmForm1.Button1Click(Sender: TObject);
var
  d,m,y:word;
  newdir:string;
  SR: TSearchRec;
  I: integer;
  Source, Desti: string;
begin
  decodedate(now,y,m,d);
  newdir:=IntToStr(d)+'_'+IntToStr(m)+'_'+IntToStr(y);
  CreateDir('C:\'+newdir);

 I := FindFirst('c:\*.*', faAnyFile, SR);
  while I = 0 do begin
    if (SR.Attr and faDirectory) <> faDirectory then
    begin
      Origem := 'c:\' + SR.Name;
      Destino := 'c:\'+newdir+'\' + SR.Name;
      try
      CopyFile(PChar(Source), PChar(Desti), False); // ---< Copia >---
      DeleteFile('c:\' + SR.Name); // ---< Exclui >---
      except
      end;
    end;
    I := FindNext(SR);
  end;
end;

It copys then deletes right after
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9765494
in this case
calinutz should get the points
(because the beginning is identical)

meikl ;-)
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9765957
Should he? Or should it really be up to the author who gets the points? I would suggest the latter myself, bearing in mind my solution was first and did what he wanted! ;-)

Geoff M.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9766192
oh yes, partial, maybe splitting points between you both
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 287
code issue 8 100
I want to use librsync in my Delphi backup application. 3 30
Installshield for Embarcadero EX 10.1 Berlin 4 20
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now