SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Miami, FL
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Clear up a UNIX question, and help me with a Ruby function

    I'd like to know, is it true that there's a limit to how many folders you can have within a directory before UNIX goes haywire (or something to that effect?)

    For instance, right now in an app I've got it set up so when a user creates an account, a folder is created for them (the folder named after their username.) If I'm User1, a new folder is created under:

    /images/users/User1

    Hypothetically, if there are 10 million users, there will be 10 million folders in that directory. If the UNIX thing is really an issue, this sounds like a huge problem.

    If it's true, the simple solution I would use would be to break it up into more directories. User1 would create the following folder:

    /images/users/u/s/e/User1

    Or something like that. Now for the Ruby question: I'm still fairly new to Ruby, but I'd like to know (or a link to a reference) what code I would use to be able to grab the first letter, second letter, then third letter of the username so I can create directories for it. I would have just searched the web, but I don't really know what the shorthand term would be for "code I would use to be able to grab the first letter, second letter..."

    I just need that snippet of code that lets me get the first, second, etc. letters from a strong, the rest I can take care of. Thanks!

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The number of descriptors per directory is a constant in a header file that gets compiled in with the OS kernel. It'll be in tens of thousands at minimum. I'd not worry about it until you have an actual problem.

    Not knowing Ruby, the first two places I'd start in answering your second question:
    1) Can you treat a string like an array and index into it the same way? Try it.
    2) Substring.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Miami, FL
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes! Substring, that's what I was looking for.

    So, going with something like: @user.name[0,1] works well. Thanks Dan.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •