pr_wainwright
asked on
Checking paths for folders > 8 charaters long.
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\pr ogram - would not be ok as 'foldername' and 'subfolder' are greater than 8 charaters long.
Thanks
Paul.
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\pr
Thanks
Paul.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you can use ExtractShortPathName() function to convert filename to short 8.3 form
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;
function PathContainsLongName(Path:
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;
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 ?
begin
if ExtractShortPathName(path)
end;
hacibumbala, is this less functional than your version ?
another version
function PathContainsLongName(path : string) : boolean;
begin
result := not (path = ExtractShortPathName(path) );
end;
this works only with paths that really exist
function PathContainsLongName(path : string) : boolean;
begin
result := not (path = ExtractShortPathName(path)
end;
this works only with paths that really exist
Hi ZhaawZ,
Your solution is good idea, really short and fast. but as you said it will only work for paths that really exist.
Your solution is good idea, really short and fast. but as you said it will only work for paths that really exist.
function PathContainsLongName(Path:
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;