1.通过索引excel表将文件进行文件夹分类的脚本,此脚本由于将ip和id对应并生成对应id的文件夹将文件进行分类,也可以任意规定表格内容,通过vul_sc_ip.txt和xlsx文件进行索引。

# -*- coding:utf8 -*-
import sys
import os
import pandas as pd
import shutil
import stat def find(path,ip):
# open the excel file
df = pd.read_excel(path)
if ip in df["ip1"].values:
s1 = df[df["ip1"]==ip]["man"].values.tolist()[0]
return {s1:ip}
else:
return 0
def mkdir(path,filename,desname):
path = path.strip()
path = path.rstrip("\\")
path_e = str(path) + '\\' + filename.decode('utf-8') + '_' + desname
isExists = os.path.exists(path_e)
if not isExists:
os.makedirs(path_e)
print (path_e + ' 创建成功'.decode('utf-8'))
return path_e
else:
print (path_e + ' 目录已存在'.decode('utf-8'))
return path_e def save(rootdir,newpath,ip):
list = os.listdir(rootdir)
ip_name = ip+'.html'
all_path_name = []
for i in range(0, len(list)):
path = os.path.join(rootdir, list[i])
all_path_name.append(os.path.basename(path))
s_media = os.path.join(rootdir,'media')
d_media = os.path.join(newpath,'media')
isExists_media = os.path.exists(d_media)
if not isExists_media:
shutil.copytree(s_media,d_media)
else:
print (d_media + ' 目录已存在'.decode('utf-8'))
if ip_name in all_path_name:
dst_path = os.path.join(rootdir,ip_name)
newfp = os.path.join(newpath,ip_name)
isExists_newfp = os.path.exists(newfp)
if not isExists_newfp:
shutil.copy(dst_path, newfp)
print ("copy %s -> %s"%(dst_path,newfp))
else:
print (newfp + ' 文件已存在'.decode('utf-8'))
else:
return 0 if __name__ == "__main__": path_report = "D:"#需要分类的文件路径
file_name = "文件名"#每个文件夹的名字
path_xlsx = "D:/ip.xlsx"#索引表路径
host_path = "D:/"#保存文件夹的位置
f = open("vul_sc_ip.txt", 'r')#索引的txt文件,由于此脚本是根据ip索引的所以txt内为IP地址
all_ip = f.readlines()
f.close()
for each_ip in all_ip:
dict_name = find(path_xlsx,each_ip.strip('\n'))
for des_name in dict_name.keys():
new_path = mkdir(path_report,file_name,des_name)
#print new_path
save(host_path,new_path,dict_name.get(des_name))

2.读取指定目录下所有文件名的脚本:

#!/usr/bin/env python
# -*- coding:utf8 -*- import os f = open("ip.txt", 'w+') def file_name(file_dir):
for root, dirs, files in os.walk(file_dir): print >>f,(files) #当前路径下所有非目录子文件 file_name('D:/')

Python--通过索引excel表将文件进行文件夹分类的脚本+读取指定目录下所有文件名的脚本的更多相关文章

  1. python获取指定目录下所有文件名os.walk和os.listdir

    python获取指定目录下所有文件名os.walk和os.listdir 觉得有用的话,欢迎一起讨论相互学习~Follow Me os.walk 返回指定路径下所有文件和子文件夹中所有文件列表 其中文 ...

  2. python中获取指定目录下所有文件名列表的程序

    http://blog.csdn.net/rumswell/article/details/9818001 # -*- coding: utf-8 -*-#~ #------------------- ...

  3. iOS案例:读取指定目录下的文件列表

    // // main.m // 读取指定目录下的文件列表 // // Created by Apple on 15/11/24. // Copyright © 2015年 Apple. All rig ...

  4. Python读取指定目录下指定后缀文件并保存为docx

    最近有个奇葩要求 要项目中的N行代码 申请专利啥的 然后作为程序员当然不能复制粘贴 用代码解决.. 使用python-docx读写docx文件 环境使用python3.6.0 首先pip安装pytho ...

  5. 遍历并读取指定目录下的所有文件内容,写入Map集合然后输出在控制台和本地文件

    public class FileWrite { public static void main(String[] args) throws Exception { //封装数据源目录 File sr ...

  6. SAS 读取指定目录下文件列表宏

    OPTIONS PS=MAX LS=MAX NOCENTER SASMSTORE=SASUSER MSTORED MAUTOSOURCE;/*获取指定文件夹的指定类型的所有文件*/%MACRO GET ...

  7. TDirectory.GetFiles获取指定目录下的文件

    使用函数: System.IOUtils.TDirectory.GetFiles 所有重载: class function GetFiles(const Path: string): TStringD ...

  8. php获取指定目录下的所有文件列表

    在我们实际的开发需求中,经常用到操作文件,今天就讲一下关于获取指定目录下的所有文件的几种常用方法: 1.scandir()函数 scandir() 函数返回指定目录中的文件和目录的数组. scandi ...

  9. unity 读取excel表 生成asset资源文件

    做unity 项目也有一段时间了,从unity项目开发和学习中也遇到了很多坑,并且也从中学习到了很多曾经未接触的领域.项目中的很多功能模块,从今天开始把自己的思路和代码奉上给学渣们作为一份学习的资料. ...

随机推荐

  1. Django 代码初体验

    其实Django中的代码逻辑就是和我们以前所学的一些项目差不多 就是 解耦.解耦.解耦 创建过后的Django文件 其中的day68是你的 项目的名字的相同的一个自动生成的文件里面都是放置配置文件类似 ...

  2. android(2)——Structure of an Android Application

    1 structure of an android application An Android application is primarily made up of three pieces: t ...

  3. ASP.NET Core 2.1以上 Bootstrap 4前端模板文件,开发环境与发布环境前端模板 environment的使用

    笔者的前端文件如下 笔者增加Bootstrap 4 和 FontAwersome(字体图标),因为Bootsrap 4已经不再包含图标了. ASp.Net Core 中,通常在 _Layout.csh ...

  4. python3 邮件,多用户,抄送

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2017/8/19 10:44 # @Author : Lys # @Site : # ...

  5. 深入浅出SharePoint——常用的url命令

    ?&displaymode=design  页面可编辑

  6. August 09th 2017 Week 32nd Wednesday

    Find hope from despair, life will become brilliant. 从绝望中寻找希望,人生终将辉煌. Have you ever seen the movie Ba ...

  7. iOS亮屏解锁命令【iOS自动化测试】--使用ssh

    前提:iOS越狱手机一个 越狱方法:使用pp助手, 爱思助手等 1.从Cydia安装以下软件: AppSync for iOSx(可安装破解软件).afc2add补丁(可访问整个iOS设备的系统文件) ...

  8. codeforces 811E Vladik and Entertaining Flags(线段树+并查集)

    codeforces 811E Vladik and Entertaining Flags 题面 \(n*m(1<=n<=10, 1<=m<=1e5)\)的棋盘,每个格子有一个 ...

  9. Google的Python代码格式化工具YAPF详解

    平时习惯了杂乱无章地编写代码,而最后的代码勘定,却依赖于PyCharm自带的格式化工具,以及其自带的提示功能来规范代码.而pycharm里的格式化工具,不支持对多文件进行代码批量格式化,曾经尝试些解决 ...

  10. Pygame碰撞检测

    学习自小甲鱼视频教学(笔记) 功能实现: 在随机位置生成若干个小球以随机速度运动: 若小球运动出左边界则从右边界进入,上下边界同理: 若两小球相碰撞则都以相反速度运动分开. 代码如下: 1.尝试自己写 ...