Access text file

Ashu_bhatt
Ashu_bhatt Member Posts: 28
Hi All,

Is there anyway of accessing a text file filename by just knowing the initials of file name. Say for example i want to access all files starting with name PDMS in a predetermined folder and then i want to rename it.

Say if i have following files

PDMS_20070206_1325_1.TXT
PDMS_20070206_1327_1.TXT
PDMS_20070206_1019_1.TXT

Thanks

Comments

  • remco_rausch
    remco_rausch Member Posts: 68
    I think you might want to have a look at the File record. This can be used to find files. For your case it would be something like:

    Files.SETRANGE(path,'c:\import\');
    Files.SETRANGE("Is a file",TRUE);
    IF Files.FIND('-')
    REPEAT


    UNTIL Files.next = 0;

    This will go through all the files in the folder. If you want to only see files that have a specific string, either specifiy a filter on the Name field or use the strpos function.

    Remco
  • Ashu_bhatt
    Ashu_bhatt Member Posts: 28
    Thanks that answers my question.

    But i have to rename file also but file table is read-only. :-s
  • remco_rausch
    remco_rausch Member Posts: 68
    Create a variable of type file

    File.Rename(OldName,newName);
  • Ashu_bhatt
    Ashu_bhatt Member Posts: 28
    It says that file table is read-only
  • Miklos_Hollender
    Miklos_Hollender Member Posts: 1,629
    OK there is a misunderstanding here - some file functions are hidden by the invisible object "file". Actually it's not so invisible, it's in the F5 menu, in all uppercase (FILE).

    Therefore never create a variable that's called File...

    So if your variable is Files and not File then File.RENAME(old, new) will wotk (with full path).

    BTW I found this topic by chance because I have to scan the contents of a directory and to me the File table always shows empty on forms and it's COUNT is 0 ... I didn't understand it... but I tried it like in this topic, using just FIND/NEXT and apparently that works. Weird. It's clearly not like f.e. the Date table.