Saved Bookmarks
| 1. |
Solve : Append file extensions to a number of files? |
|
Answer» Hey all! 01 Audioslave - Revelations.mp3 Now, if you for some reason want to change the suffix from "mp3" to something like, I don't know, maybe aac. You would type something like this in the Windows command line. Code: [Select]ren *.mp3 *.aac You hit Enter and you're done. They should now be listed as... Quote 01 Audioslave - Revelations.aac It's easy when they all have something in common, like the "mp3" suffix in this case. But what if they don't have anything in the name that's common to all files? You won't be able to use any combination of wildcard characters to match the files you want. Am I right? Example 2 It's easy when they have something in common. Like this... Quote 01 Blur - Bang In this case you have "blur" as the common denominator. So you could type something like this... Code: [Select]ren *blur* *.mp3 That should add the "mp3" suffix to all files containing the word "blur". So you get... Quote 01 Blur - Bang.mp3 But what if you don't have a common denominator in all files, like in example 2? I tried typing this... Code: [Select]ren 01*;02*;03*;04*;05* *.mp3 But the command line only returned syntax error. So I tried replacing the semicolon with a plus sign, like this... Code: [Select]ren 01*+02*+03*+04*+05* *.mp3 Command line just says that the file could not be found. Inserting spaces before and after the plus sign doesn't help either. It just gives syntax error. So there doesn't seem to be a way to cheat on this. While you may be able to select multiple files using the "file+file" format, you can't use the ASTERISK character at the same time in that same command line. So I tried... Code: [Select]ren 01* *.mp3 This works, but you have to repeat it for every file. So it would be like... Code: [Select]ren 01* *.mp3 ren 02* *.mp3 ren 03* *.mp3 ren 04* *.mp3 ren 05* *.mp3 So, now I'm thinking that one may need to create a batch file. But wait a second... a batch file?... just to perform this simple task? Is that really necessary? Is there no other way around? You would still need to write the batch file. That consumes time, and while at it you may as well go ahead and add "mp3" to the files manually, one by one, in the Windows Explorer! So... Thoughts? Ideas? Let me know!Quote from: Fractalogic on August 07, 2011, 11:14:59 AM I have a bunch of mp3 files with missing file extensions. What is the best way to append the "mp3" suffix to them? You appear to like typing, judging by the length of your post, so maybe you would prefer to rename them all manually using Explorer, but if you are prone to the type of accident that strips files of their extensions, then the time spent writing a batch file, or a command-line one-liner that you can save as a text file and paste to the prompt, will soon be saved. In any case, you will only need to copy and paste the code below, making any alterations needed to fit your particular needs. Code: [Select]@for /f "delims=" %A in ( ' dir /s /b /a-d "C:\My MP3 Collection\Folder in Question" ' ) do ren "%~dpnxA" "%~nA.mp3" Note: 1. This is for the prompt. 2. If you want to use it as a batch file change the single percent signs % to double ones %% so that %A becomes %%A and %~dpnxA becomes %%~dpnxA and %~nA becomes %%~nA. 3. It operates on all files in the named folder and all files in any sub folders also. If you don't want subfolders to be affected, delete the /s switch from the DIR command in the brackets. 4. It will add the .mp3 extension to all files that do not have an extension, and it will replace any other extension with .mp3. Quote from: Salmon Trout on August 07, 2011, 12:01:33 PM You appear to like typing, judging by the length of your post, so maybe you would prefer to rename them all manually using Explorer, but if you are prone to the type of accident that strips files of their extensions, then the time spent writing a batch file, or a command-line one-liner that you can save as a text file and paste to the prompt, will soon be saved. In any case, you will only need to copy and paste the code below, making any alterations needed to fit your particular needs. I sure do! That's why I'm still stuck in DOS! Duh! I would say that my primary objective is to learn how to do things like these. I am very eager to learn as much as possible about computers in general. I have one question. What book do I need to read to UNDERSTAND the command line you just wrote? No, seriously, what type of books cover these kind of things? Is that even a command? Or is it a script?... How do you paste a line like that into CMD? As far as I know it's not possible. Enlighten me!Quote from: Fractalogic on August 07, 2011, 12:54:08 PM How do you paste a line like that into CMD? As far as I know it's not possible. Enlighten me! Get whatever you want to paste into the clipboard and then in a CMD window: Left click the icon in the top left corner then select "Edit" from the menu that appears, then finally select "paste" --- or alternatively --- If you do not have QuickEdit enabled, you can right click in the window and select "Paste" from the menu that appears. If you have QuickEdit enabled, just right click and the text will paste itself. Select QuickEdit mode from the top left hand corner icon menu - Properties - Options - Edit Options. Quote from: Salmon Trout on August 07, 2011, 01:10:50 PM Get whatever you want to paste into the clipboard and then in a CMD window: Wow! Pasting in CMD really works! How about that! Thanks! QuickEdit needs to be enabled in order to MARK and copy from CMD, right? I just tried that command line and it worked just as expected. There are no duplicates of the "mp3" suffix, so everything is okay. Except for two PICTURE files, you know the album art kind of thing. But they are still there so I can change them back manually, it's no big deal. You did warn me that this will change the extension for all files in the folder and all sub-folders to "mp3". It was my mistake. I didn't have any sub-folders by the way, so that's just fine. Now I would really like to know where I can learn more about this?...Quote from: Fractalogic on August 07, 2011, 01:27:40 PM QuickEdit needs to be enabled in order to mark and copy from CMD, right? No, it doesn't have to be enabled, it just makes it slightly quicker. To copy from a CMD window In each case I am referring to the menu you get when you left click the top left corner icon in the CMD window: Without QuickEdit enabled: Select Edit, then select Mark, then using the left mouse button, highlight (mark) the text you want to copy, then EITHER select Edit, then select Copy OR just press ENTER QuickEdit enabled: Using the left mouse button, highlight (mark) the text you want to copy, then EITHER select Edit, then select Copy OR just press ENTER As you can see, QuickEdit cuts out having to go to the window menu first. Whichever way you do this, the highlighted text reverts to unhighlighted appearance when it gets copied to the clipboard. It can then be pasted in the normal way into other windows, programs, etc. Quote Now I would really like to know where I can learn more about this?... It is hard to know where to suggest - the web is full of batch tutorial websites. I did have a book years ago called "MS-DOS Command Reference" by Microsoft Press but the modern Windows batch language has evolved beyond that - This is quite a good introductory tutorial, by Ashley J Mills at the University Of Birmingham (England), it's all over the Web in various places https://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/win32scripting/win32scripting.html Or Google for Windows CMD Tutorial, batch examples, etc. Be inventive. Take the initiative - when you are developing a script, instead of hitting a forum and asking "How do I add two numbers together?", it is quicker to search Google for "Win32 batch arithmetic" and study the hits you get. My advice is don't get too tied down with batch - if you find you have a knack for it, (or if you don't!) take a look at Visual Basic Script, (VBscript) and Windows Powershell especially. Quote from: Salmon Trout on August 07, 2011, 02:01:38 PM Take the initiative - when you are developing a script, instead of hitting a forum and asking "How do I add two numbers together?", it is quicker to search Google for "Win32 batch arithmetic" and study the hits you get. I didn't mean to say that you are not perfectly welcome to ASK any questions you like on here and I and others will be very happy to help! |
|