Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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
删除/重命名python中的文件_Python_File_Rename - Fatal编程技术网

删除/重命名python中的文件

删除/重命名python中的文件,python,file,rename,Python,File,Rename,我试图找出如何从文件名中删除某些单词。所以如果我的文件名是lolipop three fun sand,我会输入three和fun in,它们会被删除。将文件重命名为lolipop--sand。关于如何开始这项工作有什么想法吗 使用string.replace()从文件名中删除单词。然后调用os.rename()执行重命名 newfilename = filename.replace('three', '').replace('fun', '') os.rename(filename, newf

我试图找出如何从文件名中删除某些单词。所以如果我的文件名是lolipop three fun sand,我会输入three和fun in,它们会被删除。将文件重命名为lolipop--sand。关于如何开始这项工作有什么想法吗

使用
string.replace()
从文件名中删除单词。然后调用
os.rename()
执行重命名

newfilename = filename.replace('three', '').replace('fun', '')
os.rename(filename, newfilename)
使用
string.replace()
删除文件名中的单词。然后调用
os.rename()
执行重命名

newfilename = filename.replace('three', '').replace('fun', '')
os.rename(filename, newfilename)

非常感谢你。你使用什么操作系统重要吗?非常感谢。你使用什么操作系统重要吗?