Solved

Checking paths for folders > 8 charaters long.

Posted on 2003-11-20
7
313 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

12 Experts available now in Live!

Get 1:1 Help Now