<?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 Reading filenames, date and time from a directory in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/452297#M114135</link>
    <description>&lt;P&gt;In Unix&amp;nbsp; I want to list all log files names in a folder along with last modified date and time separately.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(date and time can be in any format)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected output should be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;file_name&amp;nbsp; &amp;nbsp; date&amp;nbsp; &amp;nbsp; &amp;nbsp;time&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;file1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08-04&amp;nbsp; &amp;nbsp; &amp;nbsp;13:16&lt;/P&gt;&lt;P&gt;file2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08-04&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13:17&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried below code, but not able to get date and time.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let subdir = /abc/jht/temp/ ;
filename dir pipe "ls -1 &amp;amp;subdir | grep *.log ";
data Pfile;

length filename $ 300 size $ 20 time $ 20;
infile dir truncover;
input filename size time$;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 08 Apr 2018 08:02:00 GMT</pubDate>
    <dc:creator>SandySKY</dc:creator>
    <dc:date>2018-04-08T08:02:00Z</dc:date>
    <item>
      <title>Reading filenames, date and time from a directory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/452297#M114135</link>
      <description>&lt;P&gt;In Unix&amp;nbsp; I want to list all log files names in a folder along with last modified date and time separately.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(date and time can be in any format)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected output should be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;file_name&amp;nbsp; &amp;nbsp; date&amp;nbsp; &amp;nbsp; &amp;nbsp;time&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;file1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08-04&amp;nbsp; &amp;nbsp; &amp;nbsp;13:16&lt;/P&gt;&lt;P&gt;file2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08-04&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13:17&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried below code, but not able to get date and time.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let subdir = /abc/jht/temp/ ;
filename dir pipe "ls -1 &amp;amp;subdir | grep *.log ";
data Pfile;

length filename $ 300 size $ 20 time $ 20;
infile dir truncover;
input filename size time$;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Apr 2018 08:02:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/452297#M114135</guid>
      <dc:creator>SandySKY</dc:creator>
      <dc:date>2018-04-08T08:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Reading filenames, date and time from a directory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/452310#M114138</link>
      <description>&lt;P&gt;Not sure if it could work .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;infile&lt;/SPAN&gt; dir truncover  expandtabs &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Apr 2018 12:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/452310#M114138</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-04-08T12:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Reading filenames, date and time from a directory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/452318#M114140</link>
      <description>&lt;P&gt;It is not clear - is date and time part of the filename or do you want to extract them from the unix file metadata?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at the documentation of next functions:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;DOPEN - open a directory&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;DREAD - read a filename in the directory&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;FOPEN - open a file&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;FATTR&amp;nbsp; - get file attributes&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;FCLOSE - close the file&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;DCLOSE - clse the directory&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next code demonstartes usage of those functions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path = /folders/myshortcuts/My_Folders/flat/;
filename mydir "&amp;amp;path";
data _NULL_;
  did = dopen('mydir');
  dnum = dnum(did);
  put did= dnum=;
  do i=1 to 4; /*dnum; */
     fname = dread(did,i);
     fnx = "&amp;amp;path"||fname;
     rc=filename('tmp',fname,,,'mydir');
     fid = fopen('tmp');
     put i= rc= fid= fnx=;
     if fid then do;
        fattr = finfo(fid,'Last Modified'); 
        lm = input(fattr,datetime18.);        
        put i= fattr=  lm= datetime18.;
      /*  
        infonum = foptnum(fid); put infonum=;
        do i=1 to infonum;
           infoname = foptname(fid,i);
           fattr = finfo(fid,foptname); put i= infoname = fattr=;
        end; 
      */
        fid=fclose(fid);
     end;
     rc=filename('tmp');
     rc=0; _syserr_ = 0;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Apr 2018 13:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/452318#M114140</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-04-08T13:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Reading filenames, date and time from a directory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/598746#M172699</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*MACRO TO GET ALL FILE NAMES AND DETAILS WITHIN A DIRECTORY*/
	%MACRO GET_FILE_NAMES(FILE_DIR	,COMMON_FILE_NAME ,FILE_FORMAT	,DATA_OUT);

		FILENAME LS PIPE "dir &amp;amp;FILE_DIR.&amp;amp;COMMON_FILE_NAME.*.&amp;amp;FILE_FORMAT.";
		DATA FILE_NAMES (KEEP=LIST_FILE); 
			INFILE LS PAD TRUNCOVER EXPANDTABS ; 
			INPUT FILE_NAMES $10000.;
			LIST_FILE = COMPRESS('"'||FILE_NAMES||'"');
		RUN;
		PROC SQL;	SELECT LIST_FILE 	AS LIST_FILE		INTO:	LIST_FILE_1 - 		FROM FILE_NAMES; QUIT;
		PROC SQL; 	SELECT COUNT(*) 	AS NUM_OF_SEARCHES	INTO: 	NUM_OF_SEARCHES		FROM FILE_NAMES;	QUIT;

		%DO Z = 1 %TO &amp;amp;NUM_OF_SEARCHES.;
			DATA RAW_WANT;			
				FILENAME LISA &amp;amp;&amp;amp;LIST_FILE_&amp;amp;Z..; 
				INFILE LISA TRUNCOVER ;
				FORMAT FILE_NAME $20000.;
				FILE_NAME 	= 	&amp;amp;&amp;amp;LIST_FILE_&amp;amp;Z..;
				FLIE_SIZE	=	FINFO(FOPEN('LISA') 		,'FILE SIZE (BYTES)');
				FORMAT MOD_DATE DATETIME.;
   				MOD_DATE	=	INPUT(FINFO(FOPEN('LISA')	,'LAST MODIFIED'), DATETIME.);     
   			    RIGHTS		=	FINFO(FOPEN('LISA')			,'ACCESS PERMISSION');      
		 		OWNER		=	FINFO(FOPEN('LISA')			,'OWNER NAME');      
			RUN;

			PROC APPEND DATA = RAW_WANT BASE = WANT_1 FORCE; RUN;
		%END;
		DATA &amp;amp;DATA_OUT.; 	SET WANT_1; 		RUN;
		PROC DATASETS;		DELETE WANT_1 RAW_WANT FILE_NAMES;	RUN;
	%MEND GET_FILE_NAMES;

/*INPUT PARAMETERS HERE*/
	%GET_FILE_NAMES (FILE_DIR  			= \Users\abc\Desktop\ 		/* SPECIFY THE DIRECTORY LOCATION HERE*/
				   , COMMON_FILE_NAME 	= HAVE_NAME     			/* FILE COMMON NAME, YOU CAN PUT "*" HERE TO SELECT ALL FILE NAMES*/
				   , FILE_FORMAT 		= txt 						/* FILE FORMAT,  YOU CAN PUT "*" HERE TO SELECT ALL FILE FORMATS WITHIN THE DIRECTORY*/
				   , DATA_OUT			= WANT);		   			&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 23 Oct 2019 15:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/598746#M172699</guid>
      <dc:creator>NiyiAwe1</dc:creator>
      <dc:date>2019-10-23T15:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Reading filenames, date and time from a directory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/835169#M330160</link>
      <description>&lt;P&gt;Does anyone have code similar to this that would loop through multiple all sub-directories within the path?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 13:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/835169#M330160</guid>
      <dc:creator>hollarl11</dc:creator>
      <dc:date>2022-09-26T13:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: Reading filenames, date and time from a directory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/835170#M330161</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/434783"&gt;@hollarl11&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Does anyone have code similar to this that would loop through multiple all sub-directories within the path?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Answer from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Import-all-TSV-files-in-all-subfolders/m-p/834126" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Import-all-TSV-files-in-all-subfolders/m-p/834126&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 13:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/835170#M330161</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-26T13:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: Reading filenames, date and time from a directory</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/835172#M330163</link>
      <description>&lt;P&gt;Use this &lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_self"&gt;%DIRTREE()&lt;/A&gt; macro.&lt;/P&gt;
&lt;P&gt;You can pass it multiple top level nodes if you want (separated by pipe).&lt;/P&gt;
&lt;P&gt;You can limit the number of levels of subdirectories in scans.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%dirtree
/*---------------------------------------------------------------------------
Build dataset of files in directory tree(s)
----------------------------------------------------------------------------*/
(directory    /* Pipe delimited directory list (default=.) */
,out=dirtree  /* Output dataset name */
,maxdepth=120 /* Maximum tree depth */
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Sep 2022 14:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-filenames-date-and-time-from-a-directory/m-p/835172#M330163</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-26T14:09:26Z</dc:date>
    </item>
  </channel>
</rss>

