用数字重命名文件 [英] Rename files with numbers
问题描述
我有一个包含mp3文件的文件夹,文件夹是:
C:\我共享文件夹\橡胶灵魂
文件是:
01开车我的车.mp3
02挪威wood.mp3
03你不会看到我.mp3
04无处man.mp3
..
..
..
我正在尝试将文件重命名为:
甲壳虫乐队 - 驾驶我的Car.mp3
甲壳虫乐队 - 挪威人Wood.mp3
披头士 - 你不会看到我.mp3
甲壳虫乐队 - 无处Man.mp3
..
..
..
所以我需要将文件号更改为The Beatles - ;并且大写
这个名字。
我试图创建一个函数并使用glob并重命名,但是我有了b $ b没有了...
请有人帮帮我吧,
从现在开始,谢谢......
I have one folder containing mp3 files, the folder is:
C:\My Shared Folder\Rubber Soul
And the files are:
01 drive my car.mp3
02 norwegian wood.mp3
03 you won''t see me.mp3
04 nowhere man.mp3
..
..
..
I''m trying to rename files to:
The Beatles - Drive My Car.mp3
The Beatles - Norwegian Wood.mp3
The Beatles - You Won''t See Me.mp3
The Beatles - Nowhere Man.mp3
..
..
..
So I need to change the file number to "The Beatles -" and Capitalize
the name.
I was trying to create a function and using glob and rename, but i had
no sucsses...
Could somebody help me please,
Since now, thanks...
推荐答案
10月31日, du ************ @ gmail。 com 写道:
On Oct 31, du************@gmail.com wrote:
我有一个包含mp3文件的文件夹,文件夹是:
C:\ My Shared Folder \Rubber Soul
文件是:
03你不会看到我.mp3
我正在尝试将文件重命名为:
甲壳虫乐队 - 你不见我.mp3
。
我的第一个建议是你做出更好的改变,而你需要重新命名。
。即,不要在文件名中使用空格或撇号
(或其他不友好的字符)(尽管有些
可能在这个宗教问题上不同意我)。所以对于你的情况来说,
更可解析/有用的翻译可能是:
The_Beatles _-_ You_Wont_See_Me.mp3
所以我需要将文件号更改为The Beatles -
你可能想要使用重新为了这。在你的全球文件的循环中,你的文件类似于:
re.sub(r''^ \\\\\\\\\\\\\\ s'',r''披头士乐队 - '',......)
并将名称大写。
如果你避开撇号,那么''你不会看到我''.title()会做正确的事。
正确的事情。
我正在尝试创建一个函数并使用glob和rename,但我没有任何信息......有人可以帮助我吗,
I have one folder containing mp3 files, the folder is:
C:\My Shared Folder\Rubber Soul
And the files are:
03 you won''t see me.mp3
.
I''m trying to rename files to:
The Beatles - You Won''t See Me.mp3
.
My first suggestion is that you make better changes while you''re
taking the effort to rename. I.e., don''t use spaces or apostrophes
(or other shell-unfriendly characters) in file names (though some
might disagree with me on this religious issue). So for your case a
more parse-able/useful translation might be:
The_Beatles_-_You_Wont_See_Me.mp3
So I need to change the file number to "The Beatles -"
You''ll probably want to use "re" for this. In a loop over
your glob''d files, something like:
re.sub(r''^\d\d\s'', r''The Beatles - '', ...)
and Capitalize the name.
If you avoid the apostrophe, then ''you wont see me''.title() will do
the Right Thing.
I was trying to create a function and using glob and rename, but i
had no sucsses... Could somebody help me please,
如果你需要帮助,你应该发布你试图写的解决方案
修复它。
-
_ _ ___
| V | icah | - lliott http://micah.elliott .name md*@micah.elliott.name
" " """
You should post the solution you''ve attempted to write if you want help
fixing it.
--
_ _ ___
|V|icah |- lliott http://micah.elliott.name md*@micah.elliott.name
" " """
好的,所以函数简化了没有循环:
def renamer(文件夹,带):
archive = #file to transformation
rest = archive [3:]
print band +" - ",rest.capitalize()
obs:文件名来自
cd我导入的这种方式(带空格或撇号)。
Ok, so the function simplifyed without loops:
def renamer(folder, band):
archive = #file to transform
rest = archive[3:]
print band + " -",rest.capitalize()
obs: the file names came this way(with spaces or apostrophes) from the
cd i imported.
10月31日, du ***** *******@gmail.com 写道:
On Oct 31, du************@gmail.com wrote:
...
obs:文件名以这种方式出现(带空格或撇号)来自
我导入的CD。
...
obs: the file names came this way(with spaces or apostrophes) from
the cd i imported.
首先删除它们。这是一个可能的解决方案::
#! / usr / bin / env python
import glob,os.path
uglies = glob.glob(" * .mp3")
打印''uglies:'',uglies
pretties = []
丑陋的丑陋:
song,ext = os.path.splitext(丑陋)
song = song.replace("''","")
song = song.replace(""," _")
song = song.title()
song =" The_Beatles _-_" +歌曲[3:]
song_ext =歌曲+分机
pretties.append(song_ext)
print''pretties: '',美女
#rename uglies to pretties ...
-
_ _ ___
| V | icah | - lliott http://micah.elliott.name md*@micah.elliott.name
" " """
So remove them first. Here''s a possible solution::
#! /usr/bin/env python
import glob, os.path
uglies = glob.glob("*.mp3")
print ''uglies:'', uglies
pretties = []
for ugly in uglies:
song, ext = os.path.splitext(ugly)
song = song.replace("''", "")
song = song.replace(" ", "_")
song = song.title()
song = "The_Beatles_-_" + song[3:]
song_ext = song + ext
pretties.append(song_ext)
print ''pretties:'', pretties
# rename uglies to pretties...
--
_ _ ___
|V|icah |- lliott http://micah.elliott.name md*@micah.elliott.name
" " """
这篇关于用数字重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!