Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
nua357
Python
提交
eada4f81
P
Python
项目概览
nua357
/
Python
与 Fork 源项目一致
Fork自
inscode / Python
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Python
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
eada4f81
编写于
4月 20, 2023
作者:
6
62fa018f46d67e20094f4b3e
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto commit
上级
df352508
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
74 addition
and
1 deletion
+74
-1
main.py
main.py
+74
-1
未找到文件。
main.py
浏览文件 @
eada4f81
print
(
'欢迎来到 InsCode'
)
\ No newline at end of file
print
(
'欢迎来到 InsCode'
)
# coding=gbk
import
os
def
rename_dir
(
root_dir
):
for
root
,
dirs
,
files
in
os
.
walk
(
root_dir
,
topdown
=
False
):
for
dir_name
in
dirs
:
if
"abc"
in
dir_name
:
old_path
=
os
.
path
.
join
(
root
,
dir_name
)
new_path
=
os
.
path
.
join
(
root
,
dir_name
.
replace
(
"abc"
,
""
))
os
.
rename
(
old_path
,
new_path
)
for
file_name
in
files
:
if
"abc"
in
file_name
:
old_path1
=
os
.
path
.
join
(
root
,
file_name
)
new_path1
=
os
.
path
.
join
(
root
,
file_name
.
replace
(
"abc"
,
""
))
os
.
rename
(
old_path1
,
new_path1
)
print
(
"ok2"
)
'''
import os
def rename_dir(path):
for root, dirs, files in os.walk(path, topdown=False):
for name in dirs:
if 'xxx' in name:
new_name = name.replace('xxx', 'yyy') # 'xxx'==>'yyy'
os.rename(os.path.join(root, name), os.path.join(root, new_name))
print('wanc')
'''
'''
# write changelog to file
f = open(os.path.join(os.path.expanduser('~'),"Desktop") + "
\\
changelog.txt", "w")
for i in range(len(full_path_filenames)):
if new_full_path_filenames[i] != full_path_filenames[i]:
new_path_filenames = new_full_path_filenames[i].replace(test_path,'D:\src')
path_filenames = full_path_filenames[i].replace(test_path,'D:\src')
f.write(path_filenames + "
\n
=>" + new_path_filenames + "
\n\n
")
f.close()
# write oversized names to file
f = open(os.path.join(os.path.expanduser('~'),"Desktop") + "
\\
oversize.txt", "w")
for i in range(len(new_full_path_filenames)):
if len(new_full_path_filenames[i].split("
\\
")[-1]) > 31:
f.write(new_full_path_filenames[i] + " -> " + str(len(new_full_path_filenames[i].split("
\\
")[-1])) + "
\n
")
f.close()
'''
root_dir
=
"E:
\\
1111"
rename_dir
(
root_dir
)
'''
import os,random
path1="E:
\\
1111"
for paths, dirnames, filenames in os.walk(path1,topdown=False):
print("Current path:",paths)
print("Folder in the current path:",dirnames)
print("File name in the current path:",filenames)
print("
\n
")
for filename in filenames:
filename_path=os.path.join(paths,filename)
index = filenames.find("NOES_12")
filename = filenames[:index]
new_filename = filename
new_filename_path=os.path.join(paths,new_filename)
os.rename(filename_path,new_filename_path)
print(filename_path,"===>",new_filename_path)
for dirname in dirnames:
dirname_path=os.path.join(paths,dirname)
new_dirname=str(random.randint(100,999))
new_dirname_path=os.path.join(paths,new_dirname)
os.rename(dirname_path,new_dirname_path)
print(dirname_path,"===>",new_dirname_path)
print(result)
'''
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录