0% found this document useful (0 votes)
40 views3 pages

Ifs Read Dir

This document contains prototypes and data structures for interacting with directories and files in C using system calls like stat, opendir, readdir, and closedir. It defines structures like StatDS to store file metadata and dirEnt to represent directory entries. The code uses these to open a directory, read its contents, check file types, call a function to upload matching files to a cloud folder, and close the directory.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views3 pages

Ifs Read Dir

This document contains prototypes and data structures for interacting with directories and files in C using system calls like stat, opendir, readdir, and closedir. It defines structures like StatDS to store file metadata and dirEnt to represent directory entries. The code uses these to open a directory, read its contents, check file types, call a function to upload matching files to a cloud folder, and close the directory.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

H DFTACTGRP(*NO) BNDDIR('BVSTOOLS') ACTGRP('BVSTOOLS')

****************************************************************
* Prototypes
****************************************************************
/COPY QCOPYSRC,P.G4GDRV
*
D stat PR 10I 0 EXTPROC('stat')
D filename * VALUE Options(*String)
D bufpointer * VALUE
*
D opendir PR * EXTPROC('opendir')
D dirname * VALUE options(*string)
*
D closedir PR 10I 0 EXTPROC('closedir')
D dirhandle * VALUE
*
D readdir PR * EXTPROC('readdir')
D dirp * VALUE
****************************************************************
D StatDS DS 128
D st_mode 10U 0
D st_ino 10U 0
D st_nlink 5U 0
D st_reserved1 2A
D st_uid 10U 0
D st_gid 10U 0
D st_size 10U 0
D st_atime 10U 0
D st_mtime 10U 0
D st_ctime 10U 0
D st_dev 10U 0
D st_blksize 10I 0
D st_allocsize 10I 0
D st_objtype 10A
D st_reserved2 2A
D st_codepage 5U 0
D st_ccsid 5U 0
D st_reserved3 57A
D st_ino_gen_id 10U 0
*
D dirEnt@ s *
D dirEnt ds based(dirEnt@)
D d_reserved1 16A
D d_fileno_gen_id...
D 10U 0
D d_fileno 10U 0
D d_reclen 10U 0
D d_reserved2 10I 0
D d_reserved3 8A
D d_nlsinfo 12A
D nls_ccsid 10I 0 OVERLAY(d_nlsinfo:1)
D nls_cntry 2A OVERLAY(d_nlsinfo:5)
D nls_lang 3A OVERLAY(d_nlsinfo:7)
D nls_reserv 3A OVERLAY(d_nlsinfo:10)
D d_namelen 10U 0
D d_name 640A
*
D directory S 256 INZ('/tmp/testfiles')
D gFolder S 256 INZ('/temp/testfiles')
D gFolderID S 256 INZ('0B2Sd62H63YjoM0lzanJ3Rzh5TUU')
D fileName S 256
D qualFileName S 256
D errorMsg S 256
D newFileID S 256
D id S 256 INZ('[email protected]')
D dir@ S *
D rc S 10I 0
*****************************************************************
/free
dir@ = opendir(%trimr(directory));

if (dir@ = *NULL);
//error - Directory Not Found
exsr $Return;
endif;

dirEnt@ = readdir(dir@);

dow (dirEnt@ <> *NULL);


fileName = %subst(d_name:1:d_namelen);
qualFileName = %trim(directory) + '/' + fileName;

if (stat(%trim(qualFileName):%addr(StatDS)) < 0);


//error
exsr $Return;
endif;

if (st_objtype = '*STMF') or
(st_objtype = '*DSTMF') or
(st_objtype = '*DOC');
rc = #g4gdrv_setValue('id':id:errorMsg);

// We can either use the fully qualified folder path or the ID of the
// folder we want to upload to. The latter is much faster.
//rc = #g4gdrv_setValue('upload_to_folder':gFolder);
rc = #g4gdrv_setValue('in_parent_id':gFolderID);
rc = #g4gdrv_setValue('upload_file':qualFileName);

rc = #g4gdrv_upload(newFileID:errorMsg);

if (rc < 0);


//error uploading file
exsr $Return;
endif;

endif;

dirEnt@ = readdir(dir@);
enddo;

closedir(dir@);
exsr $Return;
//***************************************************************
//* Return
//***************************************************************
begsr $Return;

*INLR = *ON;
endsr;
/end-free

You might also like