Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating a new folder

Posted on 2003-11-17
10
Medium Priority
?
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 27

Expert Comment

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

Assisted Solution

by:gmayo
gmayo earned 186 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 189 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

609 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