Delphi how to check if you have read permission on a directory

It seems to be difficult to check the read permission on a directory in Delphi 2009. Here we will see how to find the read permission in an alternate way. In later version of Delphi we have more straight way of achieving this.

Here we will try to list the files in the directory and will check the status of this to decide whether the user has read permission to this drive. We must also consider whether the directory exists as well since we are doing this in an alternate manner. Below is the code which will help us decide on whether the user has permission on the given folder.

How does it work:

We will try to list the files and folders in the directory. If the folder exists, then the FindFirst operation will return 0. If the folder does not exist, then it will return a different result. Once it returns 0, we will check the first items Attr property, this will tell us whether it is a folder or a file or something else. The first item in the result will always be the current folder. If we check the Attr then it should return a status faDirectory which has a value 16 which says it is a directory. now lets see how to check whether the folder has read permission. To do this we have to check if the Attr property is returning code 1040 or not. If the first item Attr says it is 1040 then that means we don’t have read permission on that drive.

function HavePermissionToDrive(directory : string) : Boolean;
SR: TSearchRec;
faNotAllowed : Integer;
faNotAllowed := 1040; //custom code for none.
Result := true;

if FindFirst(directory + '\*.*', faAnyFile, SR) = 0 then
  if(SR.Attr = faNotAllowed) then
   Result := false;
 Result := false;

How to move a git folder repository to git repository without losing the history.

Here in the scenario, what I have was a folder repository where users will commit the changes. Users will treat the folder which is in a network location and will commit the changes to this repository. Now I want this to be moved to a bit bucket server so that I can use the proper process to get the changes merged. Here the challenge is to retain the history of changes without losing it while porting it. Let’s see how this can be achieved. Continue reading

Libish Varghese Jacob

Libish Varghese JacobI am currently working as a lead engineer in one of the leading wind turbine manufacturing firm. I have wide range of interests and getting my hands dirty in technology is one among them. I use this platform primarily as my knowledge base. I also use this platform to share my experience and experiments so that it might help someone who is walking the way I already did. The suggestions expressed here are the best to my knowledge at the time of writing and this may not necessarily be the best possible solution. I would pretty much appreciate if you could comment on it to bring into my notice on what could have been done better.