Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 869713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:21:12+00:00 2026-05-15T10:21:12+00:00

First of all, i’m a Graphic designer so please ignore if this programming question

  • 0

First of all, i’m a Graphic designer so please ignore if this programming question seems stupid … I know this question could’ve been split into two or three smaller questions but since I’m really new to coding VB.NET it would’ve killed me trying to put together the stuff …

Directory Structure:
I have a directory structure as follows;

ad_folder
--folderA
--folderB
--folderC
--anotherFolder
--etcfolder
--afile.aspx
--anotherfile.gif
ad_code
--folderA
--folderB
--afile.aspx
--anotherfile.gif
ad_prep
--folderA
--etcfolder
--afile.aspx
--anotherfile.gif
ad_bin
--etcfolder
--afile.aspx
--anotherfile.gif
other Folder
files folder
assetsfolder
index.aspx
web.config
image.gif

Task at hand:

I want code in VB.NET to create javascript arrays of the folder contents that can then be used on the client end. I only need arrays for all folders contained in folders starting with ad_ and an array for all the base folders . like so:

var folders=["ad_folder","ad_code","ad_prep","ad_bin"];
var ad_folder=["folderA","folderB","folderC","anotherFolder","etcfolder"];
var ad_code=["folderA","folderB"];
var ad_prep=["folderA","etcfolder"];
var ad_bin=["etcfolder"];

Please note that I do not know the number of or the names of the folders, they can be different in different cases, I only have the root path. sorry for sounding stupid.

I’ll appriciate any help anyone can provide … I’m super new to programming, I’ve googled on how I can display folder contents in VB.net and the code worked but couldn’t figure out how to create the arrays and display only folders within folders starting with “ad_”.

Thankyou soooooo much … 🙂 … If anyone needs any graphic design / photoshop help … I’ll be glad to 😉 … just let me know.



UPDATE :
okay … by googling I know :

  1. System.IO.DirectoryInfo and System.IO.FileInfo to be used for getting the folders.

  2. A literal control can be used to create javascript arrays in ASP.NET. These js arrays can then be used on the client side.

  3. The pseudo for what I want would be something like;

declare path
    if path exists and is not empty then
    ' get all folders starting with 'ad_'
    ' if folders starting with 'ad_' are > 0
    ' loop through all folders starting with 'ad_'
    ' ' if this folder exists and not empty
    ' ' get all folders within this folder
    ' ' create literal control for javascript array named 'this folder's name'
    ' create literal control for javascript array called 'folders' containing names of all folders starting with 'ad_'.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:21:13+00:00Added an answer on May 15, 2026 at 10:21 am

    Edit: I saw that you worked out how to include the parent folder array but I went ahead and updated my answer to include it. I also added in the sorting you asked for, though I’m not sure if it works just like you want or not, let me know.


    I believe the code below will do what you want. The important line is the one that response writes GetJavaFolderArrays. Put this where you want the javascript arrays to output. In my example I put it inside of a javascript block, which made sense to me 🙂

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <script runat="server">
            Private dirArray As String = "var {0}=[{1}];"
    
            Protected Function GetJavaFolderArrays(ByVal RootPath As String) As String
                'get all folders starting with ad_'
                Dim adFolders() As String = Directory.GetDirectories(RootPath, "ad_*")
    
                'sort using numbers'
                Array.Sort(adFolders, New PathNumberSorter())
    
                'string builder to hold the output'
                Dim sb As New StringBuilder()
    
                'build parent folder list
                sb.AppendLine(GetADFolder("folders", adFolders))
    
                'loop through folders'
                For Each d As String In adFolders
                    sb.AppendLine(GetADFolder(Path.GetFileName(d), Directory.GetDirectories(d)))
                Next
    
                'return the string builder'
                Return sb.ToString()
            End Function
    
            Protected Function GetADFolder(ByVal ParentName As String, ByVal cf() As String) As String
                'sort the array'
                Array.Sort(cf, New PathNumberSorter())
    
                'javascript array'
                Dim jarray As String = String.Empty
    
                'loop through folders'
                For Each d As String In cf
                    jarray += String.Format("""{0}"",", Path.GetFileName(d))
                Next
    
                'remove extra ,'
                jarray = jarray.Trim(",")
    
                Dim jfinal As String = String.Format(dirArray, ParentName, jarray)
    
                Return jfinal
            End Function
    
            Friend Class PathNumberSorter
                Implements IComparer(Of String)
    
                'used for finding all numbers in string'
                Private pattern As String = "[0-9]+"
    
                Public Function Compare(ByVal x As String, ByVal y As String) As Integer Implements System.Collections.Generic.IComparer(Of String).Compare
                    'get number from x and y
                    Dim xMatch As RegularExpressions.Match = Regex.Match(Path.GetFileName(x), pattern)
                    Dim yMatch As RegularExpressions.Match = Regex.Match(Path.GetFileName(y), pattern)
    
                    If xMatch.Success And yMatch.Success Then
                        Dim xInt As Integer = Convert.ToInt32(xMatch.Value)
                        Dim yInt As Integer = Convert.ToInt32(yMatch.Value)
    
                        Return xInt.CompareTo(yInt)
                    Else
                        Return x.CompareTo(y)
                    End If
                End Function
            End Class
        </script>
        <form id="form1" runat="server">
        <script type="text/javascript">
            <%=GetJavaFolderArrays(Server.MapPath("~/"))%>
        </script>
        <div>
    
        </div>
        </form>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all there is probably a question like this already but i couldn't
First of all this is all just concept, I have no actual programming done
First of all, I don't know if this should stay in SO or go
First of all, this isn't for a keylogger, it's for an input in a
first of all i would like to say i know its probably an easy
First of all, apologize because I have seen some posts about this, but I
First of all a statement: I'm a newbie when it comes to programming for
First of all, this code , as ugly as it is, works, for all
First of all, I've read almost all topics about this. I've tried all advices
i have this code which i use in order to extract first all users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.