Identifying only the path portion of a filename

rsaritzkyrsaritzky Member Posts: 469
Hi:

Does anyone have code to extract the path portion of a filename? For example, if I have a file path /name of:

C:\My Documents\My Navision Exports\Daily Export.csv

I want to extract the value:

C:\My Documents\My Navision Exports\

Thanks
Ron

Answers

  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    txtFullPath := 'C:\My Documents\My Navision Exports\Daily Export.csv';
    FOR i := STRLEN(txtFullPath) DOWNTO 1 DO BEGIN
      IF COPYSTR(txtFullPath,i,1) = '\' THEN BEGIN
        txtPath := COPYSTR(txtFullPath,1,i);
        txtFileName := COPYSTR(txtFullPath,i + 1);
        i := 0;
      END;
    END;
    MESSAGE('Path: %1',txtPath);
    MESSAGE('Filename: %1',txtFileName);
    
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • rsaritzkyrsaritzky Member Posts: 469
    Thanks - I seem to forget the DOWNTO parameter of the FOR clause sometimes...
    Ron
  • DenSterDenSter Member Posts: 8,304
    Check out the "'Windows Script Host Object Model'.FileSystemObject" automation server, lots of good file stuff without much programming.
Sign In or Register to comment.