- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I have this logic to retrieve all file inside a folder, I want to add last modified or created date of the file inside.
Where can I add and what procedure to use? Thanks
/*FIND PATH PARENT*/
%let pathbase=G:\Shared drives\;
data filebase;
length fref $8 fname $200;
did = filename(fref,"&pathbase.");
did = dopen(fref);
do i = 1 to dnum(did);
fname = dread(did,i);
output;
end;
did = dclose(did);
did = filename(fref);
keep fname i;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @febyinkasid,
You can use the MOPEN, FINFO and FCLOSE functions:
/*FIND PATH PARENT*/ %let pathbase=G:\Shared drives\; data filebase; length fref $8 fname $200; did = filename(fref,"&pathbase."); did = dopen(fref); do i = 1 to dnum(did); fname = dread(did,i); fid=mopen(did, fname); created=input(finfo(fid,'Create Time'),nldatm200.); lastmod=input(finfo(fid,'Last Modified'),nldatm200.); rc=fclose(fid); output; end; did = dclose(did); did = filename(fref); format created lastmod e8601dt.; keep fname i created lastmod; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Thank You...
I cant retrieve the date, though there is no error in log
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It worked with a local directory on my Windows workstation. What does the PUT statement write to the log if you add it like in the modified code below?
data filebase; length fref $8 fname created lastmod $200; did = filename(fref,"&pathbase."); did = dopen(fref); do i = 1 to dnum(did); fname = dread(did,i); fid=mopen(did, fname); put fid=; created=finfo(fid,'Create Time'); lastmod=finfo(fid,'Last Modified'); rc=fclose(fid); output; end; did = dclose(did); did = filename(fref); keep fname i created lastmod; run;
I've also simplified the assignment statements for the two new variables by using their default (character!) format. Note the deletion of the FORMAT statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Oooh it workss! I think I wrote a path that consists of folder thats why.
Thank You so much
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use this macro: https://github.com/sasutils/macros/blob/master/dirtree.sas
Of just read the macro to see how it is finding the date for each file. Basically you have to open each file so that you can use the FINFO() function.
Note that FINFO() wants the NAME of the option passed to it, but the name it wants depends on the language settings of your session, so use the FOPTNAME() function to find the right name to use. Also the string returned depends on the language setting, so use the right informat to convert to a value datetime value.
lastmod = input(finfo(fid,foptname(fid, 5)), nldatm100.);