 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
| View previous topic :: View next topic |
| Author |
Message |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2625 Location: Sydney
|
Posted: Fri May 13, 2011 8:55 am Post subject: |
|
|
the main FILES@ call
| Code: |
integer function path_exists (this_path, max_limit)
!
! subroutine to find the size of "this_path"
!
character this_path*(*)
integer*4 max_limit
!
character combine_path_name*320, local_dir*320
external combine_path_name, get_file_type, files@
intrinsic len_trim
!
integer*4 file_num, nc, i
integer*2 nmax, n, type_flag(8)
character ftype*8
!
character*320, allocatable, dimension(:) :: file_name ! C320 tree name of files found
integer*2, allocatable, dimension(:) :: attr ! I2 DOS attributes
integer*2, allocatable, dimension(:) :: date ! I2 DOS date format
integer*2, allocatable, dimension(:) :: time ! I2 DOS time format
integer*4, allocatable, dimension(:) :: file_size ! I4 File size in bytes
!
nmax = 2000
if (max_limit > 10 .and. max_limit < 32768) nmax = max_limit
!
allocate ( file_name(nmax) ) ! C320 tree name of files found
allocate ( attr(nmax) ) ! I2 DOS attributes
allocate ( date(nmax) ) ! I2 DOS date format
allocate ( time(nmax) ) ! I2 DOS time format
allocate ( file_size(nmax) ) ! I4 File size in bytes
!
local_dir = combine_path_name (this_path, '*.*')
!
call files@ (local_dir, & ! C320 directory to scan
n, & ! I2 number of entries found
nmax, & ! I2 capacity of buffers
file_name, & ! C320 tree name of files found
attr, & ! I2 DOS attributes
date, & ! I2 DOS date format
time, & ! I2 DOS time format
file_size ) ! I4 File size in bytes
!
file_num = 0
do i = 1, n
!
call get_file_type (file_name(i), attr(i), type_flag)
!
if (type_flag(4) > 0) then ! 8 volume name or directory pointers [..] or [.] - ignore
ftype = 'Sys'
!
else if (type_flag(5) > 0) then ! 16 sub directory
ftype = 'dir'
!
else if (type_flag(2) > 0) then ! 2 hidden file
ftype = 'hidden'
file_num = file_num + 1
!
else ! 0 normal file, 1 read only file, 4 system file
ftype = 'file'
file_num = file_num + 1
end if
nc = len_trim (file_name(i))
write (*,fmt='(2i4,1x,a,a)') i,nc, ftype, trim (file_name(i))
!
end do
!
path_exists = n ! number of entries found in path
return
end
|
Note I use a size limit of
256 for path name (must be big enough)
5000 for number of entries (i386 will exceed that)
320 characters for a tree name
The number of files and tree length are truncated if not big enough, but still works ok.
You should test smaller and see the results. |
|
| Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8283 Location: Salford, UK
|
Posted: Mon Aug 01, 2011 2:06 pm Post subject: |
|
|
| I have changed the documentation as per the original request from Sparge. |
|
| Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8283 Location: Salford, UK
|
Posted: Mon Aug 01, 2011 2:26 pm Post subject: |
|
|
I have had an initial look at the request from JohnCampbell for a function to count the number of files in a folder.
There is a function find_file@ with some sample code in the help file that could be adapted for this purpose. |
|
| Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8283 Location: Salford, UK
|
Posted: Mon Aug 01, 2011 2:57 pm Post subject: |
|
|
I have now added a new function to the library that can be used in the following way.
| Code: |
program files
C_EXTERNAL COUNT_FILES@ 'count_files_at'(INSTRING) : INTEGER*4
integer count
count = COUNT_FILES@("c:\techsupport\")
print*, count
end program files |
You can also use the form
| Code: |
program files
C_EXTERNAL COUNT_FILES@ 'count_files_at'(INSTRING) : INTEGER*4
integer count
count = COUNT_FILES@("c:\techsupport\*.f95")
print*, count
end program files |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|