How to rename a thousand filenames in a folder?

Discussion in 'JavaScript' started by pedong, May 25, 2008.

  1. #1
    Anyone knows a script that will rename a thousand filenames in a folder..


    example: from filename samp to samp.htm
     
    pedong, May 25, 2008 IP
  2. pedong

    pedong Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    yes.. do you know how to do it?

    I really appreciate if you can help me
     
    pedong, May 25, 2008 IP
  3. aap

    aap Well-Known Member

    Messages:
    1,802
    Likes Received:
    39
    Best Answers:
    2
    Trophy Points:
    120
    #3
    In windows-> select all files -> right click any one file -> rename that file -> rest files will be automatically renamed.
     
    aap, May 25, 2008 IP
  4. pedong

    pedong Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    it's not working.. correct me if i'm wrong... when you select all files all files are highlighted.. when you right click a particular file.. is it natural that when you right click it the highlight to the other files are gone? so the one highlighted is the only filename will be renamed
     
    pedong, May 25, 2008 IP
  5. aap

    aap Well-Known Member

    Messages:
    1,802
    Likes Received:
    39
    Best Answers:
    2
    Trophy Points:
    120
    #5
    No, all files will be renamed.
     
    aap, May 25, 2008 IP
  6. phinelinda

    phinelinda Well-Known Member

    Messages:
    603
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    108
    #6
    Use the Acdsee application. It has a rename feature where you can rename whatever number of files into whatever filenames.
     
    phinelinda, May 25, 2008 IP
  7. pedong

    pedong Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    you're right i forgot to mention my OS it's Windows 98 but i tried it in Xp and it works.. but that's not the result I expected....... let say i've thousand txt filenames and i want to make it html files by adding .html at the end of it's filename.. the recent solution add an extra array type word on every filename...
     
    pedong, May 25, 2008 IP
  8. timarcher52

    timarcher52 Peon

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hmm...I dont know of a way to do this in javascript. Depending on your platform, its a simple script though.
    If windows, write a batch file you run from your DOS prompt to loop through all files in a directory, and run the move or rename command on it (can't remember if DOS has a rename or not).
    If in unix/linux/mac, write a shell script to loop through them all and run the mv command on the files to give it the new name.

    In your case, it should be easy because your not dramatically changing the strutuce of the filename, your just appending onto it.

    So in unix, the mv command would look something like:
    mv $FILENAME $FILENAME.htm

    You can probably also use any programming language to do this that your comfortable with: PERL, Java, C, PHP, etc..

    I dont think javascript will work though...If anyone knows how to manipulate the filesystem using javascript in a cross platform compatible way, please let me know I'd love to learn how that works.

    Thanks!
    Tim
     
    timarcher52, May 26, 2008 IP
  9. aap

    aap Well-Known Member

    Messages:
    1,802
    Likes Received:
    39
    Best Answers:
    2
    Trophy Points:
    120
    #9
    yaa..this method cannot change file type...it can only change file name.
     
    aap, May 26, 2008 IP
  10. pedong

    pedong Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    When you rename a file with .txt extension with .htm then it automatically changed it file type from text file to html file Am I correct?
     
    pedong, May 27, 2008 IP
  11. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    The contents of the file remain unchanged. Only the filename itself is changed.

    Additionally, opening an HTML file will open in your default browser instead of Notepad. This might make it look different, but it's still just a text file with an HTML extension.

    As far as renaming files with javascript, you would have to look into the FileSystemObject and of course, the javascript file would have to be a .js file that you run locally on your machine; script within a webpage cannot access your file system.

    Alternatively, you could just open the command prompt and type ren *. *.html (assuming that you are using Windows, the original files have no extension, and you want to give them all an HTML extension).
     
    vpguy, May 28, 2008 IP
  12. JavaPF

    JavaPF Member

    Messages:
    62
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #12
    This can easily be done with a simple Java program. PM me if you would like me to code you something quickly.
     
    JavaPF, May 29, 2008 IP
  13. chenyaniv

    chenyaniv Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    i dont thing thats possible with js, try doing it with some ani other High-level programming language.
     
    chenyaniv, May 30, 2008 IP
  14. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #14
    this is easy to do with php
     
    crath, May 30, 2008 IP
  15. pedong

    pedong Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    how to do it in php? could you give the code? thanks
     
    pedong, Jun 9, 2008 IP
  16. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #16
    shallowink, Jun 9, 2008 IP