[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Checking paths for folders > 8 charaters long.

Posted on 2003-11-20
7
Medium Priority
?
345 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

830 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