Advertisement
apometron

rename that strange char

Oct 23rd, 2011
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. *** rename1.py
  2.  
  3. import os,sys
  4. nome = sys.argv[1]
  5. final = nome.replace("_", " ")
  6. os.rename(nome, final)
  7.  
  8. *** rename2.py
  9.  
  10. #!/usr/bin/env python
  11. # coding:utf-8
  12.  
  13. import glob
  14. import sys
  15. import os
  16.  
  17. try:
  18.     parametros = sys.argv[1]
  19. except:
  20.     parametros = "*"
  21.  
  22. arquivos = glob.glob(parametros)
  23. for nome in arquivos:
  24.     novoNome = nome.replace("_", " ")
  25.     print "%s -> %s" %(nome, novoNome)
  26.     os.rename(nome, novoNome)
  27.  
  28. print "%d arquivos atingidos." %len(arquivos)
  29.  
  30. *** rename3.py
  31.  
  32. import os
  33. import sys  # sys module should be imported
  34. nome = sys.argv[1]
  35. final=""    #final is a null string
  36. for i in nome: #i refers to each char in nome
  37.     if i == "_": # there should be a "==" operator
  38.         ch = " " # a string can be assigned to a new variable
  39.                  # but after that you cannot change that value
  40.                  # of the string via the specific variable
  41.                  # because strings are invariable values
  42.     else:
  43.         ch = i
  44.     final += ch #concatenate ch to final
  45.                 #a string can be concatenated to another
  46.                 #here you are not changing the string that
  47.                 #final originally refers to, but make final refer to a
  48.                 #new concatenated string
  49. os.rename(nome, final)
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement