Options

record all item in the folder

ForeverBlueForeverBlue Member Posts: 54
Hi all,

I am doing a small program so the user can select a folder on the local and the nav will search all files in that folder and put the path into a table. I use the following code to do the job. Right now I have 2 issues: one, will create "This Automation variable has not been instantiated... " message, even it displays all the path at the message function and second, is there a easier way to tell if the item is a folder or a file? Thanks

Shellcontrol Automation 'Microsoft Shell Controls And Automation'.Shell
Folder Automation 'Microsoft Shell Controls And Automation'.Folder3
FolderItems Automation 'Microsoft Shell Controls And Automation'.FolderItems3

IF ISCLEAR(Shellcontrol) THEN
CREATE(Shellcontrol);

Folder := Shellcontrol.BrowseForFolder(0,'Choose Folder',0);
IF ISCLEAR(Folder) THEN
EXIT;
FolderItems := Folder.Items();
FolderItem := FolderItems.Item;

FOR I := 1 TO FolderItems.Count DO
BEGIN
message('%1', Folderitems.Item(I).Path);
tempRec.path := FolderItems.Item(I).Path;
tempRec.insert;
END;

(update)
Looks look this code doesn't like when user selected "Desktop".

Comments

  • Options
    klavinklavin Member Posts: 117
    Using your code example I received errors on other folders as well. Modifying it to this it worked. Give it a shot...
    MESSAGE('Item Count %1',FORMAT(FolderItems.Count));                     //Just show how many we are looking for
    FOR i := 1 TO FolderItems.Count DO BEGIN
      MESSAGE('i: %1 - %2',FORMAT(i),FolderItems.Item(i-1).Path);           //Added i counter and i-1 for the item.
      //MESSAGE('%1', FolderItems.Item(i).Path);                            //Commented out
    END;
    

    FolderItem Count will return the total number, but the Item method is zero starting index. From MSDN:

    Parameters
    iIndex [in, optional]
    Type: Variant

    The zero-based index of the item to retrieve. This value must be less than the value of the Count property.

    http://msdn.microsoft.com/en-us/library/bb787802(v=vs.85).aspx
    Is this my 100th post?
    -Lavin
    "Profanity is the one language all programmers know best."
  • Options
    ForeverBlueForeverBlue Member Posts: 54
    Wow that was a easy fix... feel so small.... ](*,) But by any chance do you know why it doesn't like the "DESKTOP" folder?
  • Options
    klavinklavin Member Posts: 117
    I'm not sure exactly what is happening, but there are special folders associated with the Desktop... Control Panel, Computer, Libraries etc. Check out some of the other properties of the FolderItem and display them to see. Maybe you can just ignore if it is a certain type... IsFolder,IsLink,Type etc...

    http://msdn.microsoft.com/en-us/library/bb787810(v=vs.85).aspx
      MESSAGE('%1 - %2',FolderItems.Item(i-1).Type,FolderItems.Item(i-1).Name);
    
    -Lavin
    "Profanity is the one language all programmers know best."
  • Options
    absolutelyfreewebabsolutelyfreeweb Member Posts: 104
    not exactly!

    folderitems.item() is the folder itself

    folderitems.item(0) is the first node inside the folder.

    to get the correct path, you would need to parse the path and remove the file name
  • Options
    armelaarmela Member Posts: 20
    Hello there. I found this post very useful and have a question.
    What if I already know the path name (folder name). Which command do I use for that ?

    Folder := Shellcontrol.BrowseForFolder(0,'Choose Folder',0);

    So in other words, I want to change the above line of code to assign the Folder variable to smth like '\\nav-sql\RSL\'

    Any ideas ?
Sign In or Register to comment.