Solved

Checking paths for folders > 8 charaters long.

Posted on 2003-11-20
7
329 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
[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
  • 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
Industry Leaders: 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!

 
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

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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