Python,单步执行文件夹(以运行脚本)
由于我不熟悉Python,所以我想我应该来这里。
无论如何,我有几个文件夹(假设有 20 个文件夹) 每个文件夹内有更多文件夹(假设每个文件夹有 5 个) 在这些文件夹中的每个文件夹中都有另一个文件夹,其中有一个我需要运行的脚本。
脚本以相同的方式运行 'ie':sh script.sh
基本上我需要为每个文件夹运行这个脚本,问题是我不知道如何进入每个文件夹(有脚本),这是 4 个级别从原始文件夹下来。
因此,总共有大约 120 个脚本需要以相同的方式运行(该脚本还返回一个数字,例如(1 表示成功,0 表示失败),我需要记录这些数字(应该不难弄清楚)
最好的方法是什么?我想我可以弄清楚检查结果,但老实说我不太熟悉Python。
为了让大家清楚,文件夹结构是这样的: 顶级(20 个左右文件夹) --> 下面 1 个(大约 5 个文件夹) ----->这5个文件夹之一下面的1(仅包含1个文件夹) --------->1 在该文件夹下(这里是脚本所在的位置)
不要问我为什么文件夹是这样构造的......哈哈。这最好在 python 2 中完成。
Since Im unfamiliar with Python I thought i'd come here.
Anyways I have several Folders (lets say 20 folders)
Within each folder is more folders (lets say 5 per)
and within EACH one of these folders is another folder, and within THAT is a script I need to run.
The script is ran the same way 'ie':sh script.sh
Basically I need to run this script for each of these folders, problem is I have no clue how to step into each folder (that has the script) which is 4 levels down from the original folder.
So there are a total of like 120 scripts that need to be ran the same way (this script also returns a number for instance (1 for success, 0 for failure) that I need to record (shouldn't be too hard to figure out)
What would be the best way to go about this? The Checking results I think I can figure out, but stepping through all these subfolders Im honestly not well versed in python to know about.
Just so everyones clear the folder structure is like this: Top Level (20 or so folders) -->1 Below (5 or so Folders) ----->1 below one of these 5 folders (only 1 folder is contained) --------->1 below that one folder (here is where the script resides)
Don't ask me why the folders are structured this way.....lol. This would be done in python 2 preferably.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有点矫枉过正,但它应该有效:
A bit overkill, but it should work: