python的rename原来这么用
本来想实践应用一下如何批量修改,后来一想怎么那么麻烦,连最基本都都不会,简化到这份上再慢慢复杂之
一开始用help(os.rename)查了该方法的用法,

出来的解释太简单了,以为路径用的是和windows一样的反斜杠,于是怎么都没修改成功

后来查了资料,别人都用的斜杠,于是就对了,说到这,打死了一只大蚊子...
>>> os.rename("D:/su/123.txt","D:/su/456.txt")
成功的改了文件名
以前好像是会用相对路径的,想想练练
>>> os.rename("/a","/mos.txt")
这样就错了,因为当前目录下的文件不用加/,去掉就改好了
然后子目录
>>> os.rename("doc/python275.chm","doc/tutorial.txt")
成功修改文件
总结一下,python的路径用的是/,而不是\,路径那么一串总是很长,能不能存到变量里面调用就行呢,怎么调用呢
python的rename原来这么用的更多相关文章
- Python os.rename() 方法
概述 os.rename() 方法用于命名文件或目录,从 src 到 dst,如果dst是一个存在的目录, 将抛出OSError.高佣联盟 www.cgewang.com 语法 rename()方法语 ...
- Data manipulation primitives in R and Python
Data manipulation primitives in R and Python Both R and Python are incredibly good tools to manipula ...
- Python 在 Terminal 中的自动补全
为了在 Terminal 中使用 Python 更加方便,在 home 目录下添加脚本 .pythonstartup,内容如下, 然后在 .bashrc 中添加 export PYTHONSTARTU ...
- 解决方案:WindowsError: [Error 2]
使用Python的rename()函数重命名文件时出现问题,提示 WindowsError: [Error 2] 错误,最初代码如下: def renameFile(filename): filePr ...
- day22_1-课前上节复习+os模块
# ********************day22_1-课前上节复习+os模块 *******************# ********************day22_1-课前上节复习+os ...
- python shutil 模块 的剪切文件函数 shutil.movemove(src, dst),换用 os.rename(sourceFile, targetFile)
Google 一搜python 剪切文件,出来shutil 这模块,网上很多人也跟疯说shutil.move(src, dst)就是用来剪切文件的,结果一试,剪切毛线,文件都复制到另一个文件夹了,源文 ...
- Rename in Batch [Python]
#!/usr/bin/python2.7 # Program: # Rename files in current folder in batch. # Date: # 2016-04-17 # Us ...
- shell function/for in/for (())/string concat/has dir/rename using regex/if(())/exit/execute command and pass value to variable/execute python
#!/bin/bash #remove the MER.*_ in file name for all the files in a dir function getdir(){ for elemen ...
- python 文件批量改名重命名 rename
path = '/Volumes/Seagate/dev/imgs/' os.chdir(path) print('cwd: ', os.getcwd()) for f in os.listdir(' ...
随机推荐
- Sphinx的配置和使用
项目中用到了,昨天老大又给讲了讲,我感觉这玩意真是强大.想把一些功能以很小的代价做好,第三方的工具是必须要掌握的. 1. 我的开发环境在Windows上,下载了sphinx-2.2.6-release ...
- IOS自定义表格UITableViewCell
在UITableView中,自定义表格,最原始是继承UITableViewCell,然后通过写代码方式去搞,但是这个费事了. 1.在storyboard中 给一个ViewController的tabi ...
- Nexus3.0.0+Maven的使用(二)
因为Nexus3.0.0与Nexus2.X系列的差别很大,所以本章节我大概讲解下Nexus3.0.0的功能使用. 1.功能介绍 1.1 Browse Server Content 1.1.1 Se ...
- IComparable<T> Vs. IComparer<T> System.Comparison<T>
Well they are not quite the same thing as IComparer<T> is implemented on a type that is capabl ...
- problem during schema create,statement create sequence act_evt_log_seq
今天在调试程序的时候出现"problem during schema create,statement create sequence act_evt_log_seq"这个错误,跟 ...
- Mysql查询英文如何严格区分大小写?
1. 前提:在Mysql数据库中进行查询时,希望英文严格区分大小写.默认情况下是不区分大小写的.2. 演示如下:在数据库表emp中,job字段中存储的值有'Engineer',现在的情况是,下面的两句 ...
- Linux分区和挂载硬盘
分区: [root@code-svn ~]# fdisk /dev/sdb WARNING: DOS-compatible mode is deprecated. It's strongly reco ...
- 魅蓝note2在ubuntu14.04下mtp模式无法自动mount的解决方法
是因为新机型没在列表里的原因. 处理方法如下: As far as I know, MTP works fine in Trusty. You can try this: Uncomment #use ...
- struts的标签库出现Failed to load or instantiate TagExtraInfo class
使用struts的标签库出现Failed to load or instantiate TagExtraInfo class 最近在使用struts标签库的时候,在eclipse开发环境中是正常的,放 ...
- QTP操作word文档
QTP可以对word文档进行操作,这里最主要展示的是向word文档写入内容,并保存的功能. Option explicit Dim wordApp Set wordApp = createobject ...