Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By just_m3.

Thread: Replace String From multiple files

  1. #1
    Member
    Join Date
    Jun 2011
    Posts
    61
    Thanks
    2
    Thanked 11 Times in 6 Posts
    Rep Power
    2

    Default Replace String From multiple files

    I Want to know is there any way to replace any string from file name in any directory on my server and save new file name in the server.
    cpanel provide rename function bt it only edit one file at a time, and i want a to rename 100s of files at a time.
    pls coding-talk experts let me know if there is any solution

  2. #2
    Senior Member just_m3.'s Avatar
    Join Date
    Feb 2010
    Location
    Romania
    Posts
    173
    Thanks
    11
    Thanked 72 Times in 27 Posts
    Rep Power
    4

    Default

    Quote Originally Posted by mansi [Only registered and activated users can see links. Click Here To Register...]
    I Want to know is there any way to replace any string from file name in any directory on my server and save new file name in the server.
    cpanel provide rename function bt it only edit one file at a time, and i want a to rename 100s of files at a time.
    pls coding-talk experts let me know if there is any solution

    Hy there :D , this is a part of code from a script that i'm developing ....

    enjoy it


    PHP Code:
    function recScan$mainDir$allData = array() )
    {
    // hide files
    $hidefiles = array(
    ".",
    "..",
    ".htaccess",
    ".htpasswd",
    "index.php",
    "php.ini",
    "error_log" ) ;

    //start reading directory
    $dirContent scandir$mainDir ) ;

    foreach ( 
    $dirContent as $key => $content )
    {
    $path $mainDir '/' $content ;

    // if is readable / file
    if ( ! in_array$content$hidefiles ) )
    {
    if ( 
    is_file$path ) && is_readable$path ) )
    {
    $allData[] = $path ;
    }

    // if is readable / directory
    // Beware ! recursive scan eats ressources !
    else
    if ( 
    is_dir$path ) && is_readable$path ) )
    {
    /*recursive*/
    $allData recScan$path$allData ) ;
    }
    }
    }

    return 
    $allData ;




    PHP Code:
    if($_GET['now'] == 'cleanfiles')
            {
                
    $allData recScan("./myfoldernamehere");

                foreach(
    $allData as $value)
                { 
    // check if is file <only renaming files not folders>

                    
    if(is_file($value))
                    {
                        
    $newFileName str_replace(array(
                            
    '%20',
                            
    '+',
                            
    '&amp',
                            
    '&lt'),'_',$value);

                        
    // not workin' ? Step on the bitch's neck remove non utf8 chars
                        
    $newFileName preg_replace('/' '[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]' .
                            
    '[0x20]' '|[\x00-\x7F][\x80-\xBF]+' '|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*' .
                            
    '|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})' '|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|' .
                            
    '(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})' '/S','_',$newFileName);
                        
    //and final this should kill the space
                        
    $newFileName preg_replace('/\s+/','',$newFileName);

                        
    /*cleaning*/
                        
    rename($value,$newFileName);
                        
    /*cleaning*/

                        //job done print the message
                        
    echo 'Old:' $value ' <b> -> </b> New: ' $newFileName '<br/>';
                    }
                }
            } 
    Someone please move this thread in codding's ..

    Added after 47 minutes:

    Just something else i have to add .. al the other folders with content should be moved on the main one beeing scanned ....
    Last edited by just_m3.; 30-04-12 at 17:30.
    arnage likes this.
    This is ten percent luck, twenty percent skill
    Fifteen percent concentrated power of will
    Five percent pleasure, fifty percent pain

    And a hundred percent reason to remember the name!

  3. #3
    Moderator arnage's Avatar
    Join Date
    May 2009
    Location
    Serbia
    Posts
    711
    Thanks
    165
    Thanked 183 Times in 80 Posts
    Rep Power
    5

    Default

    Ups i was moved the thread from Coding, sorry.
    Nice one, btw Total Commander have an option Multi-Rename-Tool which can rename files on the host also.
    <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

  4. #4
    Member
    Join Date
    Nov 2010
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    3

    Default

    just_m3 in that ur script what does it replace?

  5. #5
    Senior Member just_m3.'s Avatar
    Join Date
    Feb 2010
    Location
    Romania
    Posts
    173
    Thanks
    11
    Thanked 72 Times in 27 Posts
    Rep Power
    4

    Default

    Quote Originally Posted by arnage [Only registered and activated users can see links. Click Here To Register...]
    Ups i was moved the thread from Coding, sorry.
    Nice one, btw Total Commander have an option Multi-Rename-Tool which can rename files on the host also.
    Yeah nice one .. while coding it i made a mistake so all files from my folder moved to rot .. arround 4000 files lol , all files were moved with path addres name something like _myfolder_music_mp3_ringtones_myfile_mp3 it was a preg_replace issue . . . , but i managed to move them back with the same script that , after fixing .... i was lucky :D because all files path name was stored in sql database : D

    Added after 2 minutes:

    just_m3 in that ur script what does it replace?
    it replace/delete special chars/words and space's written in preg/str_replace rulles like &amp &lt etc ..

    also removing non utf-8 chars from file names
    Last edited by just_m3.; 30-04-12 at 20:07.
    This is ten percent luck, twenty percent skill
    Fifteen percent concentrated power of will
    Five percent pleasure, fifty percent pain

    And a hundred percent reason to remember the name!

  6. #6
    Moderator arnage's Avatar
    Join Date
    May 2009
    Location
    Serbia
    Posts
    711
    Thanks
    165
    Thanked 183 Times in 80 Posts
    Rep Power
    5

    Default

    Phe s**t happens... Well its good that its everything ok now.
    <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 8
    Last Post: 16-10-12, 16:59
  2. Preg Replace acting very strange ???
    By something else in forum Site / Script testing and error fixing
    Replies: 7
    Last Post: 05-03-12, 11:49
  3. Help-Php replace characters
    By Sifat3d in forum Coding Forum
    Replies: 5
    Last Post: 29-08-11, 12:09
  4. A php expert ques?(replace file comments)
    By prakash55 in forum Coding Forum
    Replies: 5
    Last Post: 29-01-11, 12:18
  5. A php expert ques?(replace file comments)
    By prakash55 in forum General Discussion
    Replies: 5
    Last Post: 25-01-11, 01:06

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
  •  

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19