sgoupil
22nd September 2015, 21:03
Hello, using baanIVc4 on unix, I am trying to process files from a specific directory, without knowing the file names. I want to process each files in there one by one and delete them after being processed, any trics or ideas? Thanks.

bhushanchanda
22nd September 2015, 21:37
Hi,

You can do ls command for the directory and store the output to a text file and then read each line of that output file using seq.* functions. Once closed, use seq.unlink() or rm command to remove the file.

Or, go for dir.* functions. Which includes dir.open() followed by dir.entry() and then dir.close() Take a look - > Link (http://www.baanboard.com/programmers_manual_baanerp_help_functions_directory_file_operations_dir_entry)

vahdani
25th September 2015, 14:53
You should be able to use dir.open() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_directory_file_operations_dir_open), dir.entry() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_directory_file_operations_dir_entry) and dir.close() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_directory_file_operations_dir_close)functions.


fd=dir.open(directory.name)
|Get first file name
filename = dir.entry(fd, TDIR, rt, size, mode)

while (not isspace(filename))
do.something.with.file(filename)
|Get next file name
filename=dir.entry(fd, TDIR, rt, size, mode)
endwhile
dir.close(fd)

günther
28th September 2015, 08:11
The dir.* functions are easy to use. The only thing to remember: You get the directory entries in the order they stored in the directory. On unix boxes, you can try this:

mkdir /tmp/foo; cd /tmp/foo; >A; >B; >C; rm A; >D

=> You will get D, B, C.

If you have a requiremend to process files in the order they were created, (and you are on Unix) you can use fd=pipe.open("/bin/ls -tr ") and then seq.gets(..., fd), too.

Regards
Günther