-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheckDirectoryTest.py
More file actions
30 lines (26 loc) · 1.1 KB
/
checkDirectoryTest.py
File metadata and controls
30 lines (26 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/python
# -*- coding:utf-8 -*-
# 遍历特定目录,确定其根目录
import os
import time
import platform
def getdirectorynameFromFullName(fullDirectoryName):
"""获取不同操作系统上全路径的目录名"""
sysstr = platform.system()
if sysstr == 'Windows':
return fullDirectoryName[fullDirectoryName.rfind('\\') + 1:]
else:
return fullDirectoryName[fullDirectoryName.rfind('/') + 1:] # linux系统
localtime = time.strftime("%Y%m%d", time.localtime())
currentworkspace = os.getcwd()
processDirector = ('log', 'log2')
for root, dirs, files in os.walk(currentworkspace):
for dir in dirs:
if dir == localtime:
print("当前路径下所有子目录: %s" % dir) # 当前路径下所有子目录
print("根目录 is ::%s" % root)
#对根目录处理下只获取目录
rootdirectory = getdirectorynameFromFullName(root)
if rootdirectory in processDirector:
print('fuck it!')
# workpath = root + '\\' + dir # 仅适用于windows系统,linux系统的路径表示不一样