?
Solved

Checking paths for folders > 8 charaters long.

Posted on 2003-11-20
7
Medium Priority
?
333 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 500 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
Independent Software Vendors: 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 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