SRL Archive - SRL Suggestions

CreateDirectories


Shatterhand

2013-01-19 10:40:52

Example:
- we have a folder named A at C:\
- we want to create the folder named C at C:\A\B
- B does not exists so CreateDirectory('C:\A\B\C\'); wont work

Here is my solution:

CreateDirectories('C:\A\B\C\D\E\F\G\H\');

procedure CreateDirectories(const FilePath : String);
var
Folders : Array of String;
i : Integer;
begin
Folders := Explode('\',FilePath);
for i:=1 to (High(Folders)-1) do
CreateDirectory(Folders[0] + Between(Folders[0],Folders[i+1],FilePath));
CreateDirectory(FilePath);
end;

masterBB

2013-01-19 10:45:06

ForceDirectories('C:/Test2/test3/test4/');

Shatterhand

2013-01-19 10:47:53

From: masterBB
ForceDirectories('C:/Test2/test3/test4/');

Wow, wasted an hour for this. :D

masterBB

2013-01-19 10:52:43

Now I feel like an ass. Oh well, at least simba's function supports both / and \

Shatterhand

2013-01-19 10:56:41

From: masterBB
Now I feel like an ass. Oh well, at least simba's function supports both / and \

Well at least I learnt some string functions in pascal. :D