• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X PCB Editor
  3. Listing Sub Directory files

Stats

  • State Not Answered
  • Replies 3
  • Subscribers 159
  • Views 8420
  • Members are here 0
More Content

Listing Sub Directory files

karthikeyank
karthikeyank over 2 years ago

Hi

I would like to fetch sub directory files and store that files in single list. I tried by using "getDirFiles" through this function current Dir file names only fetching. its not collecting sub Dir files can anyone plz help me out.

Main DIR:

---------------------------------------------------------------------------------------------------------------------------------------

SUB DIR1:

---------------------------------------------------------------------------------------------------------------------------------------

SUB DIR 2:

---------------------------------------------------------------------------------------------------------------------------------------

Code:

procedure(DupFileFind()
FoldNames_Inp = getDirFiles(".")
foreach(FoldNames FoldNames_Inp
if(isDir(FoldNames) then
FileOut = getDirFiles(".")
println(FileOut)
)
)
)

Current Output is:

("A" "B" "chk" "chk")

("A" "B" "chk" "chk")

Expected Output is:

("a.dra" "a.pad" "a.psm")

("b.dra" "b.pad" "b.psm")

Thanks,

Karthi

  • Sign in to reply
  • Cancel
Parents
  • B Bruekers
    0 B Bruekers over 2 years ago

    Something like this should do the trick:

    defun(dirSearch (dir @key (maxdepth 5) )
        "Function to get all files from a given directory"
        "maxdepth:     when 0/nil only search highest dir. Any other number =level of subdirs to search"
        let((files name (dirFiles  getDirFiles(dir)) tmp_ext)
        unless(integerp(maxdepth) maxdepth=0)
        while( dirFiles
            name= strcat(dir "/" car(dirFiles)) ;fetch first element of filelist. Make a full path to be able to determine if directory or file.
            dirFiles = cdr(dirFiles) ;keep remainder of filelist
            cond(    
                (and( isReadable(name) isFile(name))    ;name is a file (not a directory)
                    files= cons(name files)
                )
                (and( isDir(name)  isReadable(name) not(memv(name list("." "..")))  maxdepth>0 )  ;name is a directory, not a file.
                    ;recursive call to fetch files from the directory 'name'
                    files= append(files dirSearch(name ?maxdepth (maxdepth-1)))
                )
            )
        )
        files    ;return list of files
        );let
    )

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • B Bruekers
    0 B Bruekers over 2 years ago

    Something like this should do the trick:

    defun(dirSearch (dir @key (maxdepth 5) )
        "Function to get all files from a given directory"
        "maxdepth:     when 0/nil only search highest dir. Any other number =level of subdirs to search"
        let((files name (dirFiles  getDirFiles(dir)) tmp_ext)
        unless(integerp(maxdepth) maxdepth=0)
        while( dirFiles
            name= strcat(dir "/" car(dirFiles)) ;fetch first element of filelist. Make a full path to be able to determine if directory or file.
            dirFiles = cdr(dirFiles) ;keep remainder of filelist
            cond(    
                (and( isReadable(name) isFile(name))    ;name is a file (not a directory)
                    files= cons(name files)
                )
                (and( isDir(name)  isReadable(name) not(memv(name list("." "..")))  maxdepth>0 )  ;name is a directory, not a file.
                    ;recursive call to fetch files from the directory 'name'
                    files= append(files dirSearch(name ?maxdepth (maxdepth-1)))
                )
            )
        )
        files    ;return list of files
        );let
    )

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • karthikeyank
    0 karthikeyank over 2 years ago in reply to B Bruekers

    Thanks for the reply but it shows me error 

    E- *Error* dirSearch: too few arguments (at least 1 expected, 0 given) - nil
    ERROR

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • B Bruekers
    0 B Bruekers over 2 years ago in reply to karthikeyank

    there was a small error, this works for me:

    dirSearch("c:/temp")

    defun(dirSearch (dir @key (maxdepth 5) )
    "Function to get all files from a given directory"
    "maxdepth:     when 0/nil only search highest dir. Any other number =level of subdirs to search"
    let((files name (dirFiles  getDirFiles(dir)) tmp_ext)
    unless(integerp(maxdepth) maxdepth=0)
      while( dirFiles
        name = car(dirFiles)
        dirFiles = cdr(dirFiles) ;keep remainder of filelist
        unless(memv(name list("." ".."))
          name= strcat(dir "/" name) ;fetch first element of filelist. Make a full path to be able to determine if directory or file.
          cond(    
            (and( isReadable(name) isFile(name))    ;name is a file (not a directory)
              files= cons(name files)
            )
            (and( isDir(name)  isReadable(name)   maxdepth>0 )  ;name is a directory, not a file.
              ;recursive call to fetch files from the directory 'name'
              files= append(files dirSearch(name ?maxdepth (maxdepth-1)))
            )
          )
        )
      )
      files    ;return list of files    
    );let
    )

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information