Software Development Kit (SDK) and API Discussions

Iterating over directory tree (recursively)

ROMEROJNR

Hi community,

I'm trying to fetch all the file inside a given directory recursively. Are there any easy way to implement this using the API?

example.py

import sys

sys.path.append('[omitted output]')

from NaServer import *

s = NaServer('[omitted output]', 1 , 20)

s.set_server_type('FILER')

s.set_transport_type('HTTPS')

s.set_port(443)

s.set_style('LOGIN')

s.set_vserver('[omitted output]')

s.set_admin_user('[omitted output]', '[omitted output]')

volpath = '/vol/[omitted output]'

api = NaElement('file-list-directory-iter')

api.child_add_string('path',volpath)

xi = NaElement('desired-attributes')

api.child_add(xi)

xi1 = NaElement('file-info')

xi.child_add(xi1)

xi1.child_add_string('name','<name>')

xi1.child_add_string('file-type','<file-type>')

xo = s.invoke_elem(api)

if xo.results_status() == 'failed':

    print 'Error:\n'

    print xo.sprintf()

    sys.exit(1)

print 'VMDK files on '+volpath+':\n'

for file in xo.child_get('attributes-list').children_get():

     if 'flat.vmdk' in file.child_get_string('name'):

          print file.child_get_string('name')

Thanks in advance!

1 ACCEPTED SOLUTION

ROMEROJNR

I found the answer using this same logic:

import os

def list_files(path):

          for i in os.listdir(path):

                    if os.path.isdir(path+'/'+i):

                              list_files(path+'/'+i)

                    else:

                              print path+'/'+i

View solution in original post

1 REPLY 1

ROMEROJNR

I found the answer using this same logic:

import os

def list_files(path):

          for i in os.listdir(path):

                    if os.path.isdir(path+'/'+i):

                              list_files(path+'/'+i)

                    else:

                              print path+'/'+i

View solution in original post

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public