Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: rename files

  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    97
    Thanks
    2
    Thanked 0 Times in 0 Posts

    rename files

    Hello, I have 1000 files and i would like php to rename them if they have a certain name, how can I write somthink like foreach to check every file ?

    thanks

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    If there is a certain pattern to the names, you can iterate it using a glob or globIterator/RegexIterator or DirectoryIterator with a filter.
    I'd suggest a glob; changing things during an iteration doesn't tend to be favourable, so dumping into an array with glob and traversing that with a foreach and renaming each item found in that array would be safe.


  •  

    Posting Permissions

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