Solved

Creating a new folder

Posted on 2003-11-17
10
279 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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
 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 95
Convert a string into a TDateTime 5 61
Create a path if not exists 7 78
Tembedded WB animatid gifs not animated on some pcs 2 80
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 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