Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python3批量重命名_Python_Python 3.x_Batch Rename - Fatal编程技术网

Python3批量重命名

Python3批量重命名,python,python-3.x,batch-rename,Python,Python 3.x,Batch Rename,我是python新手,正在尝试制作脚本,它通过以下模式重命名目录中的所有文件ShowName+seasionnumber+eposodenumber 此脚本获取文件名为argv[1],目录为argv[2]。然后在find_needed_parts中,它解析字符串并返回季节号、插曲号和节目名。但此脚本正在通过这样的回溯删除: Traceback (most recent call last): File "/home/usrname/Documents/renameFiles/main.py"

我是python新手,正在尝试制作脚本,它通过以下模式重命名目录中的所有文件
ShowName+seasionnumber+eposodenumber
此脚本获取文件名为
argv[1]
,目录为
argv[2]
。然后在
find_needed_parts
中,它解析字符串并返回季节号、插曲号和节目名。但此脚本正在通过这样的回溯删除:

Traceback (most recent call last):
  File "/home/usrname/Documents/renameFiles/main.py", line 38, in <module>
    main()
  File "/home/usrname/Documents/renameFiles/main.py", line 35, in main
    os.rename(pathAndFilename, os.path.join(dir, rename_name))
  File "/usr/lib/python3.5/posixpath.py", line 89, in join
    genericpath._check_arg_types('join', a, *p)
  File "/usr/lib/python3.5/genericpath.py", line 143, in _check_arg_types
    (funcname, s.__class__.__name__)) from None
TypeError: join() argument must be str or bytes, not 'builtin_function_or_method'
UPD1。 这是情人节

argv[1] = abcd E01 S09 ockoeko ko k.avi
argv[2] = .

主要问题在声明中

os.rename(pathAndFilename, os.path.join(dir, rename_name))
您使用的位置,当您可能想要

os.rename(pathAndFilename, os.path.join(direct, rename_name))

主要问题在声明中

os.rename(pathAndFilename, os.path.join(dir, rename_name))
您使用的位置,当您可能想要

os.rename(pathAndFilename, os.path.join(direct, rename_name))

如果失败,
argv[1]
argv[2]
的值是多少?在使用
os.path.join()
的行前面的for循环中,打印
dir
rename\u name
的值,您很可能会找到导致问题的原因。其中一个没有字符串值。@AbhinavSood更新了post
str(body++'S'++'E'+str(ep)+'.+ext)
如果你只需要连接字符串,比如
body++'SE'+str(ep)+'.+ext
@AzatIbrakov它的打字类型,在原始版本中必须是
rename_name=str(body++'S'+E'+str(ep)+'.+ext)
argv[1]和
argv[2]
的值是多少?在使用
os.path.join()
的行前面的for循环中,打印
dir
rename\u name
的值,您很可能会找到导致问题的原因。其中一个没有字符串值。@AbhinavSood更新了post
str(body++'S'++'E'+str(ep)+'.+ext)
如果你只需要连接字符串,比如
body++'SE'+str(ep)+'.+ext
@AzatIbrakov它的打字类型,在原始版本中必须是
rename_name=str(body++'S'+E'+str(ep)+'。+ext)