подскажите пожалуйста как из консоли сделать следующую операцию. дано: каталог1==>подкаталог2==>file1_0.jpg,file1_2.jpg,file1_3.jpg как находясь в каталоге1 командой изменить название файлов в подкаталоге2,так чтоб поменять только 1 например на знак z а остальная часть названия чтоб была
нетронутой.
В общем как сделать чтоб было каталог1==>подкаталог2==>filez_0.jpg,filez_2.jpg,filez_3.jpg
кто нибудь знает как в моем случае это будет конкретно выглядеть. Времени нет на изучение программирования пока. Нужно сделать срочно. Кто знает как это сделать именно в моем случае просьба сообщить.
спасибо очень помогло. Все получилось. А можно еще спросить как сделать чтоб так же изменить файлы токо не название а понизить регистр. Все сделать в нижнем регистре не меняя названия файлов?
#/usr/bin/python
from optparse import OptionParser
from os import rename,unlink
from os.path import exists
from re import compile,IGNORECASE,LOCALE
from sys import exit,stderr
pars=OptionParser(usage="""rxren [options] <regexp> <str> <file> [<file> ...]
Groups in <str>: \\1, \\2, ...""")
pars.add_option("-i","--icase",dest="ics",action="store_true",
default=False,help="ignore case of characters")
pars.add_option("-l","--list",dest="lst",action="store_true",
default=False,help="<file> is list of files")
pars.add_option("-o","--owrite",dest="owr",action="store_true",
default=False,help="overwrite existing file")
pars.add_option("-q","--quiet",dest="msg",action="store_false",
default=True,help="do not print messages")
(opts,args)=pars.parse_args()
if len(args)<3:
pars.print_help()
exit()
(myRex,myStr)=args[:2]
def ePrint(x):
if opts.qui:
print>>stderr,x
if opts.ics:
rex=compile(myRex,IGNORECASE+LOCALE)
else:
rex=compile(myRex,LOCALE)
if opts.lst:
flist=map(lambda x:x.rstrip("\n"),file(args[2]).readlines())
else:
flist=args[2:]
for fnm in flist:
newName=rex.sub(myStr,fnm)
if newName==fnm:
ePrint("%s: same name!"%newName)
elif exists(newName):
if opts.owr:
unlink(newName)
rename(fnm,newName)
else:
ePrint("%s: file exists!"%newName)
else:
rename(fnm,newName)
#/usr/bin/python
from optparse import OptionParser
from os import rename,unlink
from os.path import exists
from re import compile,IGNORECASE,LOCALE
from sys import exit,stderr
pars=OptionParser(usage="""rxren [options] <regexp> <str> <file> [<file> ...]
Groups in <str>: \\1, \\2, ...""")
pars.add_option("-i","--icase",dest="ics",action="store_true",
default=False,help="ignore case of characters")
pars.add_option("-l","--list",dest="lst",action="store_true",
default=False,help="<file> is list of files")
pars.add_option("-o","--owrite",dest="owr",action="store_true",
default=False,help="overwrite existing file")
pars.add_option("-q","--quiet",dest="msg",action="store_false",
default=True,help="do not print messages")
(opts,args)=pars.parse_args()
if len(args)<3:
pars.print_help()
exit()
(myRex,myStr)=args[:2]
def ePrint(x):
if opts.qui:
print>>stderr,x
if opts.ics:
rex=compile(myRex,IGNORECASE+LOCALE)
else:
rex=compile(myRex,LOCALE)
if opts.lst:
flist=map(lambda x:x.rstrip("\n"),file(args[2]).readlines())
else:
flist=args[2:]
for fnm in flist:
newName=rex.sub(myStr,fnm)
if newName==fnm:
ePrint("%s: same name!"%newName)
elif exists(newName):
if opts.owr:
unlink(newName)
rename(fnm,newName)
else:
ePrint("%s: file exists!"%newName)
else:
rename(fnm,newName)
#/usr/bin/python
from optparse import OptionParser
from os import rename,unlink
from os.path import exists
from re import compile,IGNORECASE,LOCALE
from sys import exit,stderr
pars=OptionParser(usage="""rxren [options] <regexp> <str> <file> [<file> ...]
Groups in <str>: \\1, \\2, ...""")
pars.add_option("-i","--icase",dest="ics",action="store_true",
default=False,help="ignore case of characters")
pars.add_option("-l","--list",dest="lst",action="store_true",
default=False,help="<file> is list of files")
pars.add_option("-o","--owrite",dest="owr",action="store_true",
default=False,help="overwrite existing file")
pars.add_option("-q","--quiet",dest="msg",action="store_false",
default=True,help="do not print messages")
(opts,args)=pars.parse_args()
if len(args)<3:
pars.print_help()
exit()
(myRex,myStr)=args[:2]
def ePrint(x):
if opts.qui:
print>>stderr,x
if opts.ics:
rex=compile(myRex,IGNORECASE+LOCALE)
else:
rex=compile(myRex,LOCALE)
if opts.lst:
flist=map(lambda x:x.rstrip("\n"),file(args[2]).readlines())
else:
flist=args[2:]
for fnm in flist:
newName=rex.sub(myStr,fnm)
if newName==fnm:
ePrint("%s: same name!"%newName)
elif exists(newName):
if opts.owr:
unlink(newName)
rename(fnm,newName)
else:
ePrint("%s: file exists!"%newName)
else:
rename(fnm,newName)