0

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

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by finalist
Featured Replies
  • You may try using: [code] ForceDirectories(name); [/code] Read More

  • I mean the following: [code] for i := 1 to 10 do begin value := inttostr(i); name := ('C:\TEST\' + value); ForceDirectories(name); end;[/code] I did test it by Delphi 7 and it creates the Folder [B]TEST[/B] and all the 10 Folders ( inside Test ). 100% tested and working Delphi … Read More

0

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

1

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.

Edited by finalist: n/a

0

Your a genius finalist. This works!!!

Thanks very much for helping me out :)

0

Your a genius finalist. This works!!!

Thanks very much for helping me out :)

You are welcome !

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.