Solved

Checking paths for folders > 8 charaters long.

Posted on 2003-11-20
7
316 Views
Last Modified: 2010-04-06
I wish to be able to check any path for folder or sub folder names greater than 8 characters long.

e.g.

c:\fldname\subfld\prog\ - would be ok as no folder names or sub folder names are greater than 8 charaters long.

c:\foldername\subfolder\program - would not be ok as 'foldername' and 'subfolder' are greater than 8 charaters long.

Thanks
Paul.
0
Comment
Question by:pr_wainwright
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:hacibumbala
ID: 9795401
Hope this code helps:

function PathContainsLongName(Path: String): Boolean;
var
  s: String;
  x: Integer;
begin
  Result := True;
  s := ExtractFileDrive(Path);
  if s <> '' then
    Delete(Path, 1, Length(s));
  if Path[1] = PathDelim then
    Delete(Path, 1, 1);
  x := Pos(PathDelim, Path);
  while x > 0 do
  begin
    if x > 9 then Exit;
    Delete(Path, 1, x);
    x := Pos(PathDelim, Path);
  end;
  Result := False;
end;
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 125 total points
ID: 9795994
well,

my version

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses filectrl;

function splitstr(var astring : String; Delimiter : String) : String;
var
  p : Integer;
begin
  result := '';
  if AString <> '' then
  begin
    p := pos(Delimiter,AString);
    if p > 0 then
    begin
      result := copy(AString,1,p-1);
      AString := copy(AString,p+length(Delimiter),maxLongInt);
    end
    else
    begin
      result := AString;
      AString := '';
    end;
  end;
end;

function PathContainsLongNamedFolder(APath : String; ALimit : Integer) : Boolean;
var s, se : String;
begin
  s := APath;
  result := false;
  while (s <> '') and (not result) do
  begin
    se := splitstr(s,'\');
    result := length(se) > ALimit;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var aDir : String;
begin
  if selectdirectory('Select a Directory','',aDir) then
    if PathContainsLongNamedFolder(aDir,8) then
      Showmessage('In this Path:'+#10+aDir+#10+
                  'is at least one foldername too long')
    else
      Showmessage('This Path:'+#10+aDir+#10+
                  'contains no long foldernames');

end;

end.

meikl ;-)
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 9796508
you can use ExtractShortPathName() function to convert filename to short 8.3 form
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:hacibumbala
ID: 9796673
Another version:

function PathContainsLongName(Path: String): Boolean;
var
  Drive: String;
  i: Cardinal;
begin
  Result := False;
  Drive := ExtractFileDrive(Path);
  if Drive <> '' then
    Delete(Path, 1, Length(Drive));
  if Path[1] = PathDelim then
    Delete(Path, 1, 1);
  with TStringList.Create do
  try
    Delimiter := PathDelim;
    DelimitedText := Path;
    for i := 1 to Count do
    begin
      if Length(Strings[i - 1]) > 8 then
      begin
        Result := True;
        Break;
      end;
    end;
  finally
    Free;
  end;
end;
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 9796829
function PathContainsLongName(path : string) : boolean;
begin
if ExtractShortPathName(path) <> path then result := true else result := false;
end;

hacibumbala, is this less functional than your version ?
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 9796924
another version

function PathContainsLongName(path : string) : boolean;
begin
result := not (path = ExtractShortPathName(path));
end;

this works only with paths that really exist
0
 
LVL 1

Expert Comment

by:hacibumbala
ID: 9797044
Hi ZhaawZ,

Your solution is good idea, really short and fast. but as you said it will only work for paths that really exist.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now