Forum > General

GetEnV Error

(1/2) > >>

captian jaster:
I Was Doing Some Coding and i made a Files And Folders Unit.
I was Testing My Program When It said All Directorys Found!
It went to make the file but it closed the window. I thought it was a file making error but it was because the folder was never made...

--- Code: ---Procedure GetFolders;
BEGIN
  writeln('Getting Folders...');
  Delay(1000);
  Folders.System := Fsearch('System',GetEnV('Not')); //The Thing I dont understand..
  IF(Folders.System = 'Not')Then
  begin
    writeln('Missing Directory "System"');
    writeln('Making Directory...');
    Delay(200);
    CreateDir('System');
  end;
  Folders.Other := Fsearch('Other',GetEnV('Not'));
  IF(Folders.Other = 'Not')Then
  begin
    writeln('Missing Directory "Other"');
    writeln('Making Directory');
    Delay(200);
    CreateDIR('Other');
  end;
  writeln('All Directorys Found!');
END;

--- End code ---

Ive used the GetEnV before But i dont know what i did wrong Now..

eny:

--- Quote from: captian jaster on April 02, 2010, 04:31:58 pm ---
--- Code: ---// ...
  Folders.System := Fsearch('System',GetEnV('Not')); //The Thing I dont understand..
//...

--- End code ---


--- End quote ---
Is the environment string 'Not' defined?
Do you really want to search all paths that are in the env var 'Not'?

I'd recommend (CLICK) not to write repeat yourself in code. More code = more places where it can go wrong  :)

captian jaster:
I dont understand what you mean by defined..
The Not is used so if the folder doesnt exists it will make it.
I tryed adding backslashes that didnt work either..
This is were i got the code

http://pascalprogramming.byethost15.com/lesson9.php

dfeher:
I looked where you said you got the code from. There is no 'Not' but '' used in those examples.  :)

eny:
Never copy & paste code and hope that it does what you want  :D
Why don't you use the more self-explanatory functions?
Like this...

--- Code: ---procedure CheckAndCreateDir(const pName: string);
begin
  if not DirectoryExists(pName) then
  begin
    writeln(format('Missing directory: "%s"', [pName]));
    writeln('Making directory...');
    Delay(200);
    CreateDir(pName);
  end;
end;

procedure GetFolders;
begin
  writeln('Getting Folders...');
  Delay(1000);
  CheckAndCreateDir('System');
  CheckAndCreateDir('Others');
  writeln('All Directories Found!');
end;


--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version