Solved

Folder Creating

Posted on 2003-11-03
4
184 Views
Last Modified: 2010-04-05
Hey,

I want to create a folder on runtime and if the folder exists then I want it to say "Safe Activated" or if it doesnt exist I want it to say "Creating Safe".

Heres my code but on runtime all it says is Creating Safe and when I run the program again it says Creating Safe and then when I go to find the folder its not there.

Heres my code ...

Code:
--------------------------------------------------------------------------------

procedure TForm1.FormCreate(Sender: TObject);beginif DirectoryExists('c:\Windows\datafile\25672567\safe')thenshowmessage (' Safe Activated ')elseshowmessage (' Creating safe ');CreateDir ('c:\Windows\datafile\25672567\safe')end;  

--------------------------------------------------------------------------------


Cheers,

Computer Programer
0
Comment
Question by:computerprogramer
[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
  • 3
4 Comments
 
LVL 5

Expert Comment

by:snehanshu
ID: 9676865
computerprogramer,
  You need to create ForceDirectories instead of create dir.
"ForceDirectories creates a new directory as specified in Dir, which must be a fully-qualified path name. If the directories given in the path do not yet exist, ForceDirectories attempts to create them."

...Shu
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9676877
So,,y, I meant you need to use ForceDirectories instead of createdir.
Also, you could add a begin  end around the else part: create a directory only if it does not exist like:
procedure TForm1.FormCreate(Sender: TObject);
begin
  if DirectoryExists('c:\Windows\datafile\25672567\safe') then
    showmessage(' Safe Activated ')
  else
  begin//create directory only if it does not exist.
    showmessage(' Creating safe ');
    ForceDirectories('c:\Windows\datafile\25672567\safe');
  end;

end;

Cheers!
...Shu
0
 
LVL 5

Accepted Solution

by:
snehanshu earned 20 total points
ID: 9676886
And, a final check for whether the directory was actually created:
procedure TForm1.FormCreate(Sender: TObject);
begin
  if DirectoryExists('c:\Windows\datafile\25672567\safe') then
    showmessage(' Safe Activated ')
  else
  begin//create directory only if it does not exist.
    If ForceDirectories('c:\Windows\datafile\25672567\safe') then
      showmessage(' Created safe ')
    else
      showmessage('!!! Create failed !!!');
  end;

end;

HTH
:-)
...Shu
0
 

Expert Comment

by:Kritsadapoj
ID: 9677492
Hi Above ....

Function Search  Directory (Copy For Use)

Function Find_File_and_Subdirectory( Dir : String );
var FindFileData : TWin32FindData;
SearchHandle : THandle;
begin
SearchHandle := FindFirstFile( PChar( Dir+'\*.*' ), FindFileData );
If SearchHandle <> INVALID_HANDLE_VALUE then
Repeat
If FindFileData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY then
Memo1.Lines.Add( '<'+FindFileData.cFileName+'>' )
else
Memo1.Lines.Add( FindFileData.cFileName );
Until Not FindNextFile(SearchHandle,FindFileData);
end;
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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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