Recursively Retrieving All the Files/Directories in a Directory

Hello,
I want to retrieve all files in a directory, and ran into this sample code:
www.ni.com/example/27157/en/
This is the function that does the retrieve action:  GetFilesAndDirectories().  Its content is as follow:
void GetFilesAndDirectories(char dir[], int* numItems, int parentItem)
char fileName[MAX_PATHNAME_LEN], searchPath[MAX_PATHNAME_LEN];
int error = 0;
strcpy (searchPath, dir);
strcat (searchPath, "\\*");
if (!GetFirstFile (searchPath, 1, 1, 0, 0, 0, 0, fileName)) // has at least one file
InsertListItem (panelHandle, PANEL_LISTBOX, -1, fileName, (*numItems)++);
while (!GetNextFile (fileName))
InsertListItem (panelHandle, PANEL_LISTBOX, -1, fileName, (*numItems)++);
if (!GetFirstFile (searchPath, 0, 0, 0, 0, 0, 1, fileName)) // has at least one directory
char dirNamesSaved[MAX_NUM_DIR][MAX_PATHNAME_LEN];
int numDir = 0, i;
strcpy (dirNamesSaved[numDir++], fileName);
while (!GetNextFile (fileName) && numDir<MAX_NUM_DIR) // first save all the directory names
strcpy (dirNamesSaved[numDir++], fileName);
for (i=0; i<numDir; i++)
char displayName[MAX_PATHNAME_LEN];
Fmt (displayName, "%s<%s%s", fileName, " (Directory)");
InsertListItem (panelHandle, PANEL_LISTBOX, -1, displayName, (*numItems)++);
MakePathname (dir, dirNamesSaved[i], searchPath);
GetFilesAndDirectories(searchPath, numItems, (*numItems)-1);
I then modify that function into one that I can use to retrieve either files or folders, and populate a ring object with the result.  I call it Ring_Populate().  Its content is as follow:
void Ring_Populate (int panel, int TargetRing, char TargetFolder[], int Directory_Bool, int *Iteration_Now, int Iteration_Prev)
char FileName [260]; //standard = 260 max char. w/ null char.
char Folder [260];
strcpy (Folder, TargetFolder); //copy string
strcat (Folder, "*"); //add wildcard character, * or ?
switch (Directory_Bool)
case 0: //file
if (!GetFirstFile(Folder, 1, 1, 0, 0, 0, 0, FileName)) //has at least 1 file
InsertListItem (panel, TargetRing, -1, FileName, (*Iteration_Now)++);
while (!GetNextFile(FileName))
InsertListItem (panel, TargetRing, -1, FileName, (*Iteration_Now)++);
break;
default: //folder
if (!GetFirstFile(Folder, 0, 0, 0, 0, 0, 1, FileName)) //has at least 1 folder
int Folder_No = 0;
int Folder_Max = 50; //max 50 folders
char Folder_List [50][260]; //name 260 max
strcpy (Folder_List [Folder_No++], FileName); //copy first element then ++
while ( (!GetNextFile(FileName)) && (Folder_No < Folder_Max) )
strcpy (Folder_List [Folder_No++], FileName); //copy all folder names
for (int i = 0; i < Folder_No; i++)
char modFolder [260];
//Fmt (modFolder, "%s<%s%s", FileName, " (DIR)");
//InsertListItem (panel, TargetRing, -1, modFolder, (*Iteration_Now)++);
//MakePathname (TargetFolder, Folder_List [i], Folder); //recycle
//Ring_Populate (panel, TargetRing, TargetFolder, 1, Iteration_Now, (*Iteration_Now) - 1);
Fmt (modFolder, "%s<%s%s", Folder_List [i], " (DIR)");
InsertListItem (panel, TargetRing, -1, modFolder, i);
break;
It works fine.  However, the section that I commented out (modified from the sample code, which works) gives me stack overflow.
//Fmt (modFolder, "%s<%s%s", FileName, " (DIR)");
//InsertListItem (panel, TargetRing, -1, modFolder, (*Iteration_Now)++);
//MakePathname (TargetFolder, Folder_List [i], Folder); //recycle
//Ring_Populate (panel, TargetRing, TargetFolder, 1, Iteration_Now, (*Iteration_Now) - 1);
This is the original code:
char displayName[MAX_PATHNAME_LEN];
Fmt (displayName, "%s<%s%s", fileName, " (Directory)");
InsertListItem (panelHandle, PANEL_LISTBOX, -1, displayName, (*numItems)++);
MakePathname (dir, dirNamesSaved[i], searchPath);
GetFilesAndDirectories(searchPath, numItems, (*numItems)-1);
Question:
1. How do I get stack overflow?  My code is essentially the same.
2. My modified code works fine retrieving the list of folders.  I do not see the need to call the function recursively.  Can anyone explain?

Hello all,
I can't figurate how to list all the root directories
(C:/> , D:/>, E:/> etc.) in a system.
I know how to recursively check the content of a
directory and all its subdirectories when a
predefined path is defined. However what I' d like to
do is actually give the option to pick one of the
root directories to start the iteration. I have been
looking around but I can' really find anything
helpful.
If any of you has any idea on how to achieve the
above objective some clarification would be really
appreciated.
Thanks in advance for your help!How to installing the Javax.comm package

Similar Messages

  • After 10.8.3 update, time machine rebackups all the files in the home

    Yesterday evening I have updated my MacBook Pro'11 from 10.8.2 to 10.8.3
    Next time machine backup works for the whole night and now I can see that it rebackups the whole home user folder. It shows all the files in my home directory have been changed somehow. As a result, a huge amount of backup history is dropped on the time machine backup drive.
    Is it okay? Why TM thinks my 350 GB of personal files have been changed after system update?

    Ok, I didn't go in and check every file on the iMac last night when it did a full backup so will take your word for it.  Doing this once with the new install seems reasonable to me, and with the large external drives I use is not a problem...well, except for the noise the drives make for such a long time will writing the backup
    I am just happy knowing there is a good base for rebuilding the internal drive if I need it.

  • Trying to retrieve all the records from the file on desktop

    HI All
    I have one particular problem. I was given a text file which as 7000 records with length 512 each in a continues string. I Changed begining of each record with comma  in that text and saved it in .csv , when I try to upload the file into my program's internal table.
    It is still giving one record. I used
    itab_EXTRACT1 declared as
    DATA: begin of itab_extract OCCURS 0,
            extract1(512) type c,
          end of itab_extract.
    call method cl_gui_frontend_services => gui_upload
        exporting
          filename                = Xfile
        filetype                    = 'ASC'
         has_field_separator     = 'X'
        changing
          data_tab                = itab_EXTRACT1
      exceptions
        others                  = 17.
      Is there a way how to retrieve all the records into the internal table.
    Thanks
    Ravi

    Hi Ravi,
    I don't know if this is the correct solution, but I think it will work.
    Declare your internal table (itab_extract) with the maximum length which your file will occupy.
    Create another internal table (itab) with field (text) length 512.
    Populate the internal table itab_extract using GUI_UPLOAD.
    Then write this code
    l_index = 1.
    itab-text = itab_extract-extract1+0(512).
    append itab.
    do.
    n = ( l_index * 512 ) + 1.
    itab-text = itab_extract-extract1+n(512).
    append itab.
    if ( itab-text is initial ).
    exit.
    endif.
    enddo.
    Let me know if I miss anything.

  • File Adapter polls all the files from the directory when deployed again

    Hi,
    File Adapter polls all the files from the inbound directory irrespective of the timestamp when deployed again.
    For ex. when the BPEL process with file adapter is deployed, it starts polling the directory based on the timestamp as and when the directory is written with the files. I did not opt for deleting the files after read by the File Adapter.
    But, when BPEL process is modified and deployed again, this time, the file adapter picks up all the files in the inbound directory and doesn't consider the timestamp.
    My guess is that it should not pick all the files but based on timestamp only.
    I guess I can observe the same behavior if I bounce the Application Server also
    Do I have an option to achieve this?
    Thanks,
    Sasi Bhushan.

    try this:
    1- create a File object for the directory. (look at isDirectory() )
    2- create a File[] that represents the files in that directory. (.listFiles())
    3- if (file[x].isDirectory()) {recursive method call;}
    4- else {
    process file;
    If you want more help--do some work on it, and come back with specific questions relating to specific lines in your code and specific error messages you've been receiving.

  • Deletling a folder and all the files & folders in it

    Hi,
    Is there a way to delete all the files and folders in a
    directory, a custom tag or some code would help a lot.
    <cfdirectory> should have a "destroy" action which
    deletes a folder and everything in it.
    Thanks.

    I don't know why you couldn't do a <cfdirectory
    action="delete"
    recurse="yes">
    Should delete everything in subfolders, etc.....unless I'm
    misunderstanding the tag......
    Hulfy wrote:
    > Hi,
    >
    > Is there a way to delete all the files and folders in a
    directory, a custom
    > tag or some code would help a lot.
    >
    > <cfdirectory> should have a "destroy" action which
    deletes a folder and
    > everything in it.
    >
    > Thanks.
    >

  • How to read all the files in the directory

    Hi,
    I want to read all the files from a directory and perform some operations on them. How to read one file at a time from the directory. Is there any operation like the * sign in Dos and Matlab. Is there any such vi which does that.
    Thanks,
    Nitin

    I'm glad I could help, Danny.  Using the VI Server technique for recursion is very slow and memory-intensive.  I have never seen a need for recursion in LabVIEW that couldn't be solved with a loop and shift registers.
    -D
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • Not seeing all the files on a shared Windows server??

    I'm using a Windows Server 2003 to share files between Macintosh an Windows users. But sometimes the Mac users (10.4) don't see all the files (in the same folder) that the Windows users do! I've checked on the server and I don't see any (obvious) permission problem ... So why aren't all the files displayed???
    Any help is greatly appreciated!
    Jerome

    Hello Herr Jerome, I have the same problem, here in our company. We have around 70 employees connected to a windows server network. There are 68 PCs and 2 macs, one of which is mine. We have a special directory on the server called macdata, but other users place their files in their own respective directories, to which we normally have access.
    Since yesterday, if anyone else places files from PC on to the server for me, I cant see them. I can see all other files but not the ones copied since yesterday.Our support guys have tried pretty much everything including resetting permissions, to no avial. finally they received an error message: Caution older mac systems will have problems reading more than 65000 (plus a few files). But there are in advance of 100 000 files on our server, but the extra 35 000 wernt put on there just yesterday.I´m running Macosx 10.4.11 which is by no means an old system.
    I´ve spent the day hunting the Internet for a solution, but Info on this subject seem to be scarce! I mean this is a very big problem in a business environment, our IS dept has been trying to scrap the macs for years and I´ve been working here on a mac and fighting for 15 years. So now our IS has at last a valid reason for switching us to PCs.
    I don´t understand Apple not publishing these limitions in a prominent spot on their website, not to mention a solution because it´s a crucial limitation, people should know about. Apple truely is not interested in corporate, nor in its truly loyal champions bravely fighting aganst the PC onslaught

  • I had Partitioned my Macintosh HD, so now it has two, Macintosh HD and Macinyosh HD 2, but the question is, my computer has an minor update OS X 10.8.2 to 10.8.3, i wan to move all the files as BACKUP to the Macintosh HD 2, but how? Thanks.

    I had Partitioned my Macintosh HD, so now it has two, Macintosh HD and Macinyosh HD 2, but the question is, my computer has an minor update OS X 10.8.2 to 10.8.3, i wan to move all the files as BACKUP to the Macintosh HD 2, but how? Thanks.

    As long as the Macintosh HD 2 partition is just the same size as Macintosh HD to avoid problems in the future, then you can clone one to the other using Carbon Copy Cloner, then use Disk Utility to Repair Permissions on both and if you need too you can hold the option key down while booting and select the #2 partition to boot from.
    However you need to set CCC to maintain a pure clone, or else by default it will save the changes between clone updates and overfill your #2 partition.
    Also the #2 is merely a bootable backup alternative and for retrieving the rarely occuring deleted files, don't use #2 for storage or anything you want to save pernamently.
    In addition you also need external clones and backups, as the machine may fail or get lost etc.,
    Most commonly used backup methods

  • Getting all the files on my computer

    Hi,
    I have written an algorithm which reads my harddrive from root, and goes all the files and folders and stores them in a index. I am using it for a project that gets all the folders and displays them in a explorer like Tree.
    heres the algorithm below.
    File[] files = new File[10000];  //Contains all the files read
    int[] index = new int[10000];  //Contains a position of the root folder that file is in, in relation to files[]
    int count = 0;
    //---First part of code
    count = 0;   //how many files and folders read so far
    File[] getfiles = File.listRoots(); //Gets al the root drives
    readfiles(getfiles[3]);  //Reads drive (i read my E:\ drive as its the smallest)
    //--- Second part of code
    private void readfiles(File folder) {
          File[] getfiles = folder.listFiles();   //gets files within that folder
          int i = 0;                         //for looping        
          int fold = count;             //Remebers this number as it has the index for the folder the files contained in
          while (true) {
            try {
              files[i+count] = getfiles; //saves the file details
    index[i+count] = fold; //Saves the index of the folder it is contained in, so that it can be easily positioned in a tree
    if (files[i+count].isDirectory()) {    //checks if directory
    readfiles(files[i+count]); //repeats the loop wih the new folder
    i++;
    } catch (IndexOutOfBoundsException ioobe) {break;} //no more files to read kills the loop
    count = count + i; //updates the count to stop writing over data
    Hope i have documented it ok,
    Heres the problem.
    When i run it, it works perfect, but i see no folders, just files. I think my algorithm is writing over it but i tries and i get "null" errors when reading the data in other bits of code.
    OK, well thanks in advance
    I can post the whole code if needed but its kinda messy as i have left code in there for reference.

    I wanted to index the whole drive for 2 reasons...
    1. So that it can be put into a tree, so that the user
    can go through the files as if they were using the
    windows explorer tree menu thingyBut you don't need to put the whole file hierarchy into a single data structure to do that.
    2. My program is going to be a back up program, and it
    would use the index for comparisions and stuff.OK, but I'd suggest in this case, you may want to consider whether you need the whole thing in memory at a single time. It may be easier to compare recursively between dynamically created/loaded values. I suppose it'll depend on how you store the survey between invocations of the program.

  • Hi, my laptop just crashed and I was unable to retrieve all the pictures saved in it. However, I have a backup on my iPod touch. Is it possible to sync pictures from my iPod to my laptop? Thanks.

    Hi, my laptop just crashed and I was unable to retrieve all the pictures saved in it. However, I have a backup on my iPod touch. Is it possible to sync pictures from my iPod to my laptop? Thanks.

    Sync with "new" computer
    https://discussions.apple.com/docs/DOC-3141

  • I am running out of memory on my hard drive and need to delete files. How can I see all the files/applications on my hard drive so I can see what is taking up a lot of room?

    I am running out of memory on my hard drive and need to delete files. How can I see all the files/applications on my hard drive so I can see what is taking up a lot of room?
    Thanks!
    David

    Either of these should help.
    http://grandperspectiv.sourceforge.net/
    http://www.whatsizemac.com/
    Or search 'disk size' in the App Store.
    Be carefull with what you delete & have a backup BEFORE you start, you may also want to reboot to try to free any memory that may have been written to disk.

  • How to transfer file from ipod touch to i tunes. i have files in my ipod , ut itunes is  new so its telling if u sync the ipod all the files will be replaced but no files in the itunes.. so kindly help me how to transfer the files  from i pod to itunesb

    how to transfer file from ipod touch to i tunes. i have files in my ipod , ut itunes is  new so its telling if u sync the ipod all the files will be replaced but no files in the itunes.. so kindly help me how to transfer the files  from i pod to itunes......

    Some of the information below has subsequently appeared in a document by turingtest2: Recovering your iTunes library from your iPod or iOS device - https://discussions.apple.com/docs/DOC-3991
    Your i-device was not designed for unique storage of your media. It is not a backup device and media transfer was designed for you maintaining a master copy of your media on a computer which is itself properly backed up against loss. Syncing is one way, computer to device, updating the device content to the content on the computer, not updating or restoring content on a computer. The exception is iTunes Store purchased content.
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer - http://support.apple.com/kb/HT1848 - only media purchased from iTunes Store
    For transferring other items from an i-device to a computer you will have to use third party commercial software. Examples (check the web for others; this is not an exhaustive listing, nor do I have any idea if they are any good):
    - Senuti - http://www.fadingred.com/senuti/
    - Phoneview - http://www.ecamm.com/mac/phoneview/
    - MusicRescue - http://www.kennettnet.co.uk/products/musicrescue/
    - Sharepod (free) - http://download.cnet.com/SharePod/3000-2141_4-10794489.html?tag=mncol;2 - Windows
    - Snowfox/iMedia - http://www.mac-videoconverter.com/imedia-transfer-mac.html - Mac & PC
    - iexplorer (free) - http://www.macroplant.com/iexplorer/ - Mac&PC
    - Yamipod (free) - http://www.yamipod.com/main/modules/downloads/ - PC, Linux, Mac [Still updated for use on newer devices? No edits to site since 2010.]
    - 2010 Post by Zevoneer: iPod media recovery options - https://discussions.apple.com/message/11624224 - this is an older post and many of the links are also for old posts, so bear this in mind when reading them.
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive - https://discussions.apple.com/docs/DOC-3141 - dates from 2008 and some outdated information now.
    Copying Content from your iPod to your Computer - The Definitive Guide - http://www.ilounge.com/index.php/articles/comments/copying-music-from-ipod-to-co mputer/ - Information about use in disk mode pertains only to older model iPods.
    Get Your Music Off of Your iPod - http://howto.wired.com/wiki/Get_Your_Music_Off_of_Your_iPod - I am not sure but this may only work with some models and not newer Touch, iPhone, or iPad.
    Additional information here https://discussions.apple.com/message/18324797

  • Reading all the files from Application Server in a specific folder

    Hi,
    I want to read all the files present in a folder on Application Server ( AL11 ). My problem is that I do not know the name of the file but I know the folder path where files are present.
    I need to go to this folder and pick up all the files present in this folder and then process these files in my program.
    Can any one help me in this!
    Regards,
    Lalit

    You can use a call to
    C_DIR_READ_START'
    and
    CALL 'C_DIR_READ_NEXT'
    Regards,
    John.

  • HT4889 I have accidentally created another account when using Migration Assistant to a new MBA. How do I now 'migrate' all the files from both accounts into one to save myself having two accounts, both of which are me? Help?

    I have accidentally created another account when using Migration Assistant to a new MBA. I have read that I probably should not have skipped migration in the initial set up and the problem would have been avoided but, alas, here I am. Does anyone know how I can 'migrate' all the files from one of the accounts that has been created to the other, so then I can delete it and have a single user on the computer seeing as I am the only person using it? I have read starting again, if this is the way to go, where is the best place to start 'starting again'?

    Yes definitely should see it but its not coming up (I don't think) when I log out of 2nd user and into the main account. Opening finder in the 2nd account, I can obviously find the public folder because thats where I dropped all the files, but when in the main account, it can't be found. The only public folder that comes up is the folder for that account (main account) and it does not display files I'm looking for. Frustrating....
    EDIT: Have found it through a round-about way but all music and photo and movie etc files have a red stop sign disallowing them from being transferred. Can you guess what the next question will be?

  • How do I merge two accounts into one account that contains all the files from both?

    When I was running my MacBook Pro under Snow Leopard, I had one account for business that was encripted and another account that was unencripted for personal.  Now, under Lion, the whole disc gets encripted so I don't really need two acounts.  How do I merge the accounts together into one account and retain all the files from both?
    Thanks,
    Dave

    Somethinkg like these?

Maybe you are looking for

  • Options in running Windows from an mSATA drive

    I recently ordered an x220 and expect to receive it this week. I also ordered an mSATA drive that I would like to install. Once I have it installed, I am not sure the best method to install Windows to the new drive and would appreciate some feedback.

  • How much will it cost to repair the headphone jack on my iPod video?

    I have no warranty but the part is like $6 on amazon so it cant be much. I love this iPod and I have used it every day since it came out. I would hate for it to go to waste.

  • How to avoid select query in loop

    Hi All, I have to select entries from table iclpay looping it_dfkkop and delete the entries in it_dfkkop_tmp which are not present in iclpay. For this If use below code its working fine, but there is performance issue     CLEAR: it_iclpay[],it_iclpay

  • Regarding Searh option in table control

    Hello, I have one table control in which i have taken only one field of 132 length so that user enter the line wise comments in that table control. Now i want a search button for that table control so that user can enter any string to search in the t

  • Set up end user notification for updates/comments

    Hi, SCSM 2012 R2 I've set up a workflow to notify end users when an incident has been created. Users can submit cases by mail, get a receipt, and can reply to the incident. Now, i'd like to set up a workflow to notify end users when a comment has bee