This method returns the directory list for the path specified where SAS is running

def dirlist(self, path):
        """
        This method returns the directory list for the path specified where SAS is running
        """

        code = """
        data _null_;
         spd = '""" + path + """';
         rc  = filename('saspydir', spd);
         did = dopen('saspydir');

         if did > 0 then
            do;
               memcount = dnum(did);
               put 'MEMCOUNT=' memcount;
               do while (memcount > 0);
                  name = dread(did, memcount);
                  memcount = memcount - 1;

                  qname = spd || '"""+self.hostsep+"""' || name;

                  rc = filename('saspydq', qname);
                  dq = dopen('saspydq');
                  if dq NE 0 then
                     do;
                        dname = strip(name) || '"""+self.hostsep+"""';
                        put 'DIR=' dname;
                        rc = dclose(dq);
                     end;
                  else
                     put 'FILE=' name;
               end;

            put 'MEMEND';
            rc = dclose(did);
            end;
         else
            do;
               put 'MEMCOUNT=0';
               put 'MEMEND';
           end;

         rc = filename('saspydq');
         rc = filename('saspydir');
        run;
        """

        if self.nosub:
            print(code)
            return None
        else:
           ll = self.submit(code, results='text')

        dirlist = []

        l2 = ll['LOG'].rpartition("MEMCOUNT=")[2].partition("\n")
        memcount = int(l2[0])

        l3 = l2[2].rpartition("MEMEND")[0]

        for row in l3.split(sep='\n'):
            i = row.partition('=')
            if i[0] in ['FILE', 'DIR']:
                dirlist.append(i[2])

        if memcount != len(dirlist):
            print("Some problem parsing list. Should be " + str(memcount) + " entries but got " + str(
                len(dirlist)) + " instead.")

        return dirlist