Recent

Author Topic: problems with createdir  (Read 1618 times)

frederic

  • Full Member
  • ***
  • Posts: 226
problems with createdir
« on: July 23, 2017, 03:30:27 pm »
dear specialist

i want to be able to create folders during runtime ( the folders will be filled by the same program with text files);
I made following procedure but that did not work.
When i create  the ALevel folder by hand then it works,but that is not what i want.
In the "createdir description"it says:

Quote
If the directory doesn't contain an absolute path, then the directory is created below the current working directory.

so i create a path ,exclusive the textfilename.





 
Code: Pascal  [Select][+][-]
  1. procedure TForm1.createmyfoldersbtnClick(Sender: TObject);
  2. var n ,intnow,intdatum:integer;
  3.        dubnow:double;
  4.         datstr:string;
  5. begin
  6.      dubnow:=now;
  7.      intnow:=trunc(now);
  8.  
  9.      for n:=0 to 10 do
  10.      begin
  11.          intdatum:=n+ intnow;
  12.          datstr:='c:\users\public\ALEVEL\myfolder'+inttostr(intdatum)+'\';
  13.  
  14.          if  directoryexists(datstr) then   memo1.lines.add (datstr+ 'cannot be to created ' )
  15.          else
  16.               begin
  17.               if  CreateDir (datstr) then  memo1.lines.add ('succesfull create '+datstr)
  18.                 else    memo1.lines.add (datstr + '___create  failed');
  19.              end;
  20.  
  21.      end;//for
  22. end;            


What is wrong here?

frederic

« Last Edit: July 23, 2017, 04:36:41 pm by frederic »

balazsszekely

  • Guest
Re: problems with createdir
« Reply #1 on: July 23, 2017, 03:54:17 pm »
Why it fails? Try
Code: Pascal  [Select][+][-]
  1. if  CreateDir (datstr) then
  2.   memo1.lines.add ('succesfull create '+datstr)
  3. else
  4.   memo1.lines.add (SysErrorMessage(GetLastOSError));

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: problems with createdir
« Reply #2 on: July 23, 2017, 04:02:29 pm »
What is wrong here?

The first thing hurts my eyes: Your indentation is terrible! Without proper indentation you'll never see the structure of your program, and logical errors will occur.

But this is not the issue here. I tested your routine, and it did not create the subfolders either. In my case, certainly because the intermediate folder ALEVEL did not exist. Try "ForceDirectories" instead of "CreateDir", it creates all the intermediate directories of a path, if required. It did work in my test.

frederic

  • Full Member
  • ***
  • Posts: 226
Re: problems with createdir
« Reply #3 on: July 23, 2017, 04:40:12 pm »
getmem,wp
thanks ,

i used  "ForceDirectories" and it worked

frederic

 

TinyPortal © 2005-2018