Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *** rename1.py
- import os,sys
- nome = sys.argv[1]
- final = nome.replace("_", " ")
- os.rename(nome, final)
- *** rename2.py
- #!/usr/bin/env python
- # coding:utf-8
- import glob
- import sys
- import os
- try:
- parametros = sys.argv[1]
- except:
- parametros = "*"
- arquivos = glob.glob(parametros)
- for nome in arquivos:
- novoNome = nome.replace("_", " ")
- print "%s -> %s" %(nome, novoNome)
- os.rename(nome, novoNome)
- print "%d arquivos atingidos." %len(arquivos)
- *** rename3.py
- import os
- import sys # sys module should be imported
- nome = sys.argv[1]
- final="" #final is a null string
- for i in nome: #i refers to each char in nome
- if i == "_": # there should be a "==" operator
- ch = " " # a string can be assigned to a new variable
- # but after that you cannot change that value
- # of the string via the specific variable
- # because strings are invariable values
- else:
- ch = i
- final += ch #concatenate ch to final
- #a string can be concatenated to another
- #here you are not changing the string that
- #final originally refers to, but make final refer to a
- #new concatenated string
- os.rename(nome, final)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement