<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: List of files in a directory filename, timestamp, size in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/757816#M239235</link>
    <description>&lt;P&gt;For each file, define file references with FILENAME(), open the file with &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p1fr3ny0ek8sr9n1pujj2om3bia7.htm" target="_blank" rel="noopener"&gt;FOPEN()&lt;/A&gt;, and then use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p0cpuq4ew0dxipn1vtravlludjm7.htm" target="_blank" rel="noopener"&gt;FINFO()&lt;/A&gt; to retrieve file metadata.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Jul 2021 17:17:48 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-07-28T17:17:48Z</dc:date>
    <item>
      <title>List of files in a directory filename, timestamp, size</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/757791#M239228</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to a list of files in a specific directory with names and timestamps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below code. But it only outputs filenames and &lt;STRONG&gt;not&lt;/STRONG&gt; other wanted information eg. created or changed timestamp. Nice to have as well size of the files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data &amp;amp;_OUTPUT1.;&lt;BR /&gt;length fref $8 fname $200;&lt;BR /&gt;did = filename(fref,'/sas/data/Logs');&lt;BR /&gt;did = dopen(fref);&lt;BR /&gt;do i = 1 to dnum(did);&lt;BR /&gt;fname = dread(did,i);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;did = dclose(did);&lt;BR /&gt;did = filename(fref);&lt;BR /&gt;keep fname;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 16:49:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/757791#M239228</guid>
      <dc:creator>ANLYNG</dc:creator>
      <dc:date>2021-07-28T16:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: List of files in a directory filename, timestamp, size</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/757816#M239235</link>
      <description>&lt;P&gt;For each file, define file references with FILENAME(), open the file with &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p1fr3ny0ek8sr9n1pujj2om3bia7.htm" target="_blank" rel="noopener"&gt;FOPEN()&lt;/A&gt;, and then use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p0cpuq4ew0dxipn1vtravlludjm7.htm" target="_blank" rel="noopener"&gt;FINFO()&lt;/A&gt; to retrieve file metadata.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 17:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/757816#M239235</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-28T17:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: List of files in a directory filename, timestamp, size</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/757817#M239236</link>
      <description>&lt;P&gt;Look at the documentation for the FINFO function. Once you have an individual file identifier you use that function to get the bits of information that are available.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p0cpuq4ew0dxipn1vtravlludjm7.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p0cpuq4ew0dxipn1vtravlludjm7.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The operating system determines which items are available and in what order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or parse output from an OS command like DIR (windows) or LS (unix/linux)&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 17:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/757817#M239236</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-28T17:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: List of files in a directory filename, timestamp, size</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/757824#M239239</link>
      <description>&lt;P&gt;This is an example that works on UNIX (as University Edition runs on a Linux instance):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fdata;
length
  fref dref $8
  fname $200
;
rc = filename(dref,'/folders/myfolders');
did = dopen(dref);
if did
then do;
  do i = 1 to dnum(did);
    fname = dread(did,i);
    rc = filename(fref,'/folders/myfolders/' !! fname);
    fid = fopen(fref);
    if fid
    then do;
      size = finfo(fid,foptname(fid,6));
      modified = finfo(fid,foptname(fid,5));
      output;
      rc = fclose(fid);
    end;
    rc = filename(fref);
  end;
  rc = dclose(did);
end;
rc = filename(dref);
keep fname size modified;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will have to convert the resulting character values to numbers.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 17:33:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/757824#M239239</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-28T17:33:31Z</dc:date>
    </item>
    <item>
      <title>Re: List of files in a directory filename, timestamp, size</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/758139#M239359</link>
      <description>&lt;P&gt;It is a nice solution. however it display an error with this message Code = 11. - ERROR: Resource is write-locked by another user. File ****System Error Code = 11. I thinks it has problems reading information for files which is in use. it is log files on a running system. is there an easy way to exclude the running files and display the rest?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 16:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/758139#M239359</guid>
      <dc:creator>ANLYNG</dc:creator>
      <dc:date>2021-07-29T16:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: List of files in a directory filename, timestamp, size</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/758295#M239410</link>
      <description>&lt;P&gt;Please post your SAS log - what statement causes that error?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It should be possible to test for that error to avoid the DATA step failing.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 00:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/758295#M239410</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-07-30T00:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: List of files in a directory filename, timestamp, size</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/758334#M239437</link>
      <description>here is some of the log - hope the errtos can be avoided. I get however data out when I run it now.&lt;BR /&gt;&lt;BR /&gt;211 /*---- Start of User Written Code ----*/&lt;BR /&gt;212&lt;BR /&gt;213 data &amp;amp;_OUTPUT1.;&lt;BR /&gt;214 length&lt;BR /&gt;215 fref dref $8&lt;BR /&gt;216 fname $200&lt;BR /&gt;217 ;&lt;BR /&gt;218 rc = filename(dref,'/sas/config/compute/Lev1/SASLogs');&lt;BR /&gt;219 did = dopen(dref);&lt;BR /&gt;220 if did&lt;BR /&gt;7 The SAS System 08:53 Friday, July 30, 2021&lt;BR /&gt;&lt;BR /&gt;221 then do;&lt;BR /&gt;222 do i = 1 to dnum(did);&lt;BR /&gt;223 fname = dread(did,i);&lt;BR /&gt;224 rc = filename(fref,’/sas/config/compute/Lev1/SASLogs/' !! fname);&lt;BR /&gt;225 fid = fopen(fref);&lt;BR /&gt;226 if fid&lt;BR /&gt;227 then do;&lt;BR /&gt;228 size = finfo(fid,foptname(fid,6));&lt;BR /&gt;229 modified = finfo(fid,foptname(fid,5));&lt;BR /&gt;230 output;&lt;BR /&gt;231 rc = fclose(fid);&lt;BR /&gt;232 end;&lt;BR /&gt;233 rc = filename(fref);&lt;BR /&gt;234 end;&lt;BR /&gt;235 rc = dclose(did);&lt;BR /&gt;236 end;&lt;BR /&gt;237 rc = filename(dref);&lt;BR /&gt;238 keep fname size modified;&lt;BR /&gt;239 run;&lt;BR /&gt;&lt;BR /&gt;INFO: Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation can result.&lt;BR /&gt;228:7 size&lt;BR /&gt;229:7 modified&lt;BR /&gt;ERROR: Resource is write-locked by another user. File&lt;BR /&gt;/sas/config/compute/Lev1/SASLogs/XXXX_2021.07.30_05.56.26.log. System Error Code = 11.&lt;BR /&gt;ERROR: Resource is write-locked by another user. File&lt;BR /&gt;=/sas/config/compute/Lev1/SASLogs/XXXX_2021.07.30_05.56.30.log. System Error Code = 11.&lt;BR /&gt;ERROR: Resource is write-locked by another user. File&lt;BR /&gt;=/sas/config/compute/Lev1/SASLogs/XXXX _2021.07.30_06.16.&lt;BR /&gt;25.log. System Error Code = 11.&lt;BR /&gt;</description>
      <pubDate>Fri, 30 Jul 2021 07:01:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/758334#M239437</guid>
      <dc:creator>ANLYNG</dc:creator>
      <dc:date>2021-07-30T07:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: List of files in a directory filename, timestamp, size</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/758378#M239453</link>
      <description>&lt;P&gt;Here's a macro that will work on both UNIX and WINDOWS and does not require XCMD:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://core.sasjs.io/mp__dirlist_8sas.html" target="_blank"&gt;https://core.sasjs.io/mp__dirlist_8sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To invoke:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%mp_dirlist(path=/your/dir, outds=work.ds, getattrs=YES)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jul 2021 13:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-files-in-a-directory-filename-timestamp-size/m-p/758378#M239453</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2021-07-30T13:13:31Z</dc:date>
    </item>
  </channel>
</rss>

