Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Walking a Folder Structure to gather Files/Images

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Walking a Folder Structure to gather Files/Images

    Hi,

    Looking for help in gathering all the images from a folder and sub-folders after providing a starting path and types. The code needs to auto navigate the structure looking for certain types of files (.jpg, .bmp, .avi, .mpg, .whatever) and then inserting them into a sql table.

    Is this where xbasic is needed? Any code, tutorials, and/or videos?

    I'm thinking of a form that contains 3 controls, a textbox that contains the starting path, a button that runs the process, and a multi-select list box where the user selects all the file types needed.

    Thanks,
    Stanley

    #2
    Re: Walking a Folder Structure to gather Files/Images

    Here's a function I created a while ago to do something like you are requesting. May be a good starting point for you. It loads the photo path and name, but does not load the actual photo into the table.

    'Date Created: 17-Feb-2012 09:25:13 AM
    'Last Updated: 29-May-2013 10:29:41 AM
    'Created By : 174admin148
    'Updated By : nfnportal
    FUNCTION Load_Photos_into_Photos AS C ( )
    ' Version 4, 7-17-14, By Pat
    ' This UDF loads photo info into the photos table.
    ' Looks in every project directory and checks for photos. If there are some, loads into the Photos table
    ' The unique index on directory name / photo name in the table prevents duplicates
    dim cnx as SQL::Connection
    dim crs as SQL::ResultSet
    dim args as SQL::Arguments
    dim cnx_OK as L
    dim exe_OK as L
    dim vSelect as c
    dim vInsert as c
    ' every project has 5 subdirectories
    dim vBasePath as c
    vBasePath = "c:\enefen\000_NFN_Projects"
    dim vDirectoryList as c
    vDirectoryList = <<%txt%
    Inspection
    ClientDocs
    POC
    NFNWIP
    NFNFinished
    %txt%
    dim vSubDirectory as c
    dim vProjectname as c
    dim vPhotoList as c
    vSelect="SELECT PROJECT_NUMBER, PROJECT_FULL_NAME FROM projects"
    cnx_OK = cnx.open("::name::nfn")
    if cnx_OK = .t.
    exe_OK = cnx.execute(vSelect)
    if exe_OK = .t.
    crs = cnx.ResultSet
    args.set("argFullname","Pat")
    ' look in every directory in every project
    while crs.NextRow()
    vPhotoList = ""
    vJobno = crs.data(1)
    vProjectname = crs.data(2)
    args.set("argJobno",crs.data(1))
    args.set("argProjname",crs.data(2))
    for each vDir in vDirectoryList
    args.set("arg Dir",vDir)
    vPhotoList = filefind.get(vBasePath+chr(92)+vProjectname+chr(92)+vDir+chr(92)+"*.*",0,"N")
    if len(vPhotoList)>4
    for each pic in vPhotoList
    if upper(right(pic.value,3)) = "JPG" .or. upper(right(pic.value,4)) = "JPEG" 'by policy, all are jpg
    args.set("argPicname",pic.value)
    vInsert = <<%txt%
    INSERT IGNORE INTO photos(PROJECT_NUMBER, PROJECT_FULL_NAME,PHOTO_DIRECTORY,PHOTO_NAME,DATE_ADDED,ADDED_BY)
    VALUES ( :argJobno, :argProjName,:argDir,:argPicname,curdate(),:argFullname)
    %txt%
    exe_OK = cnx.execute(vInsert,args)
    end if
    next 'each pic
    end if
    next 'next directory
    end while 'more projects
    end if 'exe_OK
    cnx.close()
    end if 'cnx_OK
    END FUNCTION
    Pat Bremkamp
    MindKicks Consulting

    Comment


      #3
      Re: Walking a Folder Structure to gather Files/Images

      Hi Pat, good to here from you... I spent a day with you to my left at the conference...

      Regarding your code, there is several places that I don't understand what's going on...
      #1.
      vDirectoryList = <<%txt%
      Inspection
      ClientDocs
      POC
      NFNWIP
      NFNFinished
      %txt%

      #2.
      You say this code only goes 5 folders deep, yet I do not see anything that enforces that. I need to search the entire hierarchy, no matter how many folders deep.

      #3.
      I see you are using "for each". How do you know when it is finished? In vfp, we start it with "for each" and end it it with an "endfor"...

      #4.
      Similar to the "for each" above, where does "end while" loop I see near the bottom start? In vfp, we start a while loop with a "do while" and end it with a "enddo", so I need some clarification.

      Thanks,
      Stanley

      Comment


        #4
        Re: Walking a Folder Structure to gather Files/Images

        Hi again Stanley
        #1
        In my case I only need to search 5 sub directories and I know what they are, so I name them explicitly. In your case, if you use filefind.get() with a different last parameter, you can get the subdirectories. Then, when there are none in the directory, you have reached the end of the tree. Look for filefind.get() in the help.

        #2
        Same as above

        #3
        In xbasic, for each ends automatically when it reaches the end of the list. No need for an "exit for", but you can use that to bail out early if you want.

        #4
        The start of the loop is "while" and the end of the loop is "end while"

        Pat
        Pat Bremkamp
        MindKicks Consulting

        Comment


          #5
          Re: Walking a Folder Structure to gather Files/Images

          Hi Pat,

          Is there a code formatter that will indent the code so its easier to read? I've copied your code to a text editor and started manually indenting it, and quite frankly its running together and not blocking out as I'd expect to see it. This would help me as I could then see the code as sections/blocks.

          I've just ordered the whole kitten-ku-buttle from Susan, which I hope will help in figuring this strange (non-traditional) language out. I say that because of all the metaphors, as traditionally we add controls to a page/form. But here we have an UX control which is the page or a control on a page. A lot of overlapping metaphors.

          Any idea where the videos/tutorials are for the grid that has children in a sub grid, that also has children in a sub grid that Doron Faber?? demo'ed somewhere? That is some power that we can use.

          And yet another question, How is the best way to change the name of a control that a genie had woven into the project? I done the "disconnected" app last night using the defaulted "list1" and "list2" controls when following along. The I decided to see how much pain Alpha could inflect on me by simple changing their names to something more meaningful like "LIST_Page" and "LIST_PartyName". Well, after 3+ hours, I still don't have it right. I found the "search the project files" menu item, but that shows the UX control that I've changed... (I already know that, as its the one that I made the changes to) I search for "LIST1" and it then shows me a lot of code in a code window where I see the old "LIST1" in the code. It is spaghetti, as I look as best as I know how at the references and I see no "LIST1" in the references. Also when running it in the browser, it errors on like line 1505. What's with that, as I have no files that has more than 20 lines of code. Where is that file, and can I edit it?

          Fustrating... any ideas,

          Stanley

          Comment


            #6
            Re: Walking a Folder Structure to gather Files/Images

            Here is a portion of my Image Management module from the Framework. I left out the part that writes the files to a JSON file.

            It specifically does not recurse folders, so you have to alter it to do that. You can swap out this line for the similar one below for starters:
            lst = filefind.get_recurse(img_fldr + chr(92) + "*.*",FILE_FIND_NOT_DIRECTORY,"PN")


            '==The script looks at the contents of the designated Images Folder.
            '==Note - the script does NOT recurse subfolders below the designated Images Folder. But you could modify the code to do this
            '==The script will weed out any non-graphic files and any that start with the Thumbnail Prefix.

            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            function post_images as c (e as p)

            dim img_fldr as c = "images"
            dim valid_img as c = ".jpg,.png,.gif,.jpeg,.bmp"
            dim thumb_prefix as c = "thumb_"
            dim app_url as c = Request.ApplicationRootUrl
            dim app_fldr as c = Request.ApplicationRoot
            dim arr[0] as p

            if a5_is_path_valid(img_fldr) = .f.
            post_images = "alert('Error - Invalid image path defined in post_images function');"
            END
            end if

            '==create list of valid images sitting in images folder

            lst = filefind.get(img_fldr + chr(92) + "*.*",FILE_FIND_NOT_DIRECTORY,"N")

            '==weed out invalid image files and thumbnails from lst
            dim lst2 as c = ""
            for each foo in lst
            if inlist2(file.filename_parse(foo,"E"),valid_img)
            if at(thumb_prefix,foo) <> 1
            lst2 = lst2 + foo + crlf()
            end if
            end if
            next
            lst = lst2

            '==add all images in default folder to table if not already in table
            dim cn as sql::Connection
            dim args as sql::Arguments
            cn.open("::name::conn")
            for each foo in lst

            fn = img_fldr + chr(92) + foo
            img_size = a5_getimagesize(fn).widthPixels + "px X " + a5_getimagesize(fn).heightPixels + "px"
            file_size = file.size(fn)

            args.add("filename",alltrim(foo))
            if sql_lookup(cn,"wt_image","filename=:filename","filename",args) = ""
            vsql = "INSERT INTO wt_image (filename) VALUES (:filename)"
            cn.execute(vsql,args)
            end if

            if file.exists(app_fldr + img_fldr + chr(92) + thumb_prefix + foo)
            vsql = "UPDATE wt_image SET thumb=1,image_size='{img_size}',file_size={file_size} WHERE filename='"+foo+"'"
            else
            vsql = "UPDATE wt_image SET thumb=0,image_size='{img_size}',file_size={file_size} WHERE filename='"+foo+"'"
            end if
            vsql = evaluate_string(vsql)
            if cn.execute(vsql) = .f.
            errorout("WT_IMAGES__LOADALLIMAGES|"+cn.callresult.text)
            end if

            next

            end function
            Steve Wood
            See my profile on IADN

            Comment

            Working...
            X