Hi all. I have another problem. Basically I have a project where I need to create a number of folders in one go. This is the code I have:

program create_folders;

uses
crt, sysutils

var
  value, name : string;
  i : integer;

begin

for i := 1 to 10 do
  begin
  value := inttostr(i)
  name := ('C:\Test\' + value);
  CreateDir(name);
  end;
end.

However it doesn't work.
What am I doing wrong?

Thanks for your time

Greg :)

Recommended Answers

All 5 Replies

You may try using:

ForceDirectories(name);

You may try using:

ForceDirectories(name);

I tired this but with no success. I want to create several different directorys each with a diffent name, e.g. Folder_1, Folder_2, Folder_3, etc.

I thought this would be possible using a for loop but it doesn't seem to work! Perhaps someone could shed some light as to why!


Thanks

Greg

I mean the following:

for i := 1 to 10 do
  begin
    value := inttostr(i);
    name := ('C:\TEST\' + value);
    ForceDirectories(name);
  end;

I did test it by Delphi 7 and it creates the Folder TEST and all the 10 Folders ( inside Test ).
100% tested and working Delphi code is:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  i:      Integer;
  name:   string;
  value:  string;
begin
  Memo1.Clear;
  for i := 1 to 10 do
  begin
    value := inttostr(i);
    name := ('C:\TEST\' + value);
    ForceDirectories(name);
    Memo1.Lines.Add(name);
  end;
end;

end.

Your a genius finalist. This works!!!

Thanks very much for helping me out :)

Your a genius finalist. This works!!!

Thanks very much for helping me out :)

You are welcome !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.