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 1102363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:10:30+00:00 2026-05-17T01:10:30+00:00

I have a directory with sitemaps, which all end with a number. I have

  • 0

I have a directory with sitemaps, which all end with a number.

I have an automatic sitemap generator script which needs to count all sitemaps in a folder using glob.

Currently I am stuck here.

What I need is to count all sitemap files which has a number in them, so I don’t count the ones without any numbers.

For instance, in my root I have a sitemap.xml file, then I also have sitemap1.xml, sitemap2.xml, sitemap3.xml etc…

I need to use glob to only return true when the filename contains a number like “sitemap1.xml”.

Is this possible?

$nr_of_sitemaps = count(glob(Sitemaps which contains numbers in their filenames)); 

Thanks

  • 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-17T01:10:30+00:00Added an answer on May 17, 2026 at 1:10 am

    To glob for files ending in <digit>.xml you can use a pattern like:

    *[0-9].xml
    

    So to count the matches, the PHP might look like:

    $count = count(glob('/path/to/files/*[0-9].xml'));
    

    If you want super-fine control (moreso than glob can give) over the matching files, you could use a general pattern then use preg_grep to filter the resulting array to precisely what you want.

    $count = count(
        preg_grep(
            '#(?:^|/)sitemap\d{1,3}\.xml$#',
            glob('/path/to/files/sitemap*.xml')
        )
    );
    

    See also: http://cowburn.info/2010/04/30/glob-patterns/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a directory structure D:\workspace 2\project\lib where I have all the files AgentMain.java(which
I have directory with > 1000 .html files, and would like to check all
I have a directory structure like the following; script.php inc/include1.php inc/include2.php objects/object1.php objects/object2.php soap/soap.php
I have a directory with several subdirectories with files. How can I copy all
I'm using playframework v2 and I have my sitemap files being re-created once a
I have a directory which consist of some different sub directory which every one
I have directory structure like following: analytics / / \ \ conf script src
I have directory that keeps a number of 3rd party libraries. It is under
I have directory that contains nearly 14,000,000 audio samples in *.wav format. All plain
I have Android application, which have directory module and it list out some of

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.