我在Java中编写了一个简单的应用程序,它采用路径列表并生成一个包含该原始列表下所有文件路径的文件.
如果我有paths.txt有:
c:\folder1\
c:\folder2\
...
...
c:\folder1000\
Run Code Online (Sandbox Code Playgroud)
我的应用程序在每个多线程路径上运行递归函数,并返回包含这些文件夹下所有文件路径的文件.
现在我想用Python编写这个应用程序.
我写了一个简单的应用程序,用于os.walk()运行给定的文件夹并打印文件路径输出.
现在我想并行运行它,我已经看到Python有一些模块:多线程和多处理.
什么是最好的做什么?在这种方式下,它是如何执行的?
我正在编写一个应用程序,它将行添加到多个线程的同一文件中.
我有一个问题,其中一些行没有新行.
对此有何解决方案?
class PathThread(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue
def printfiles(self, p):
for path, dirs, files in os.walk(p):
for f in files:
print(f, file=output)
def run(self):
while True:
path = self.queue.get()
self.printfiles(path)
self.queue.task_done()
pathqueue = Queue.Queue()
paths = getThisFromSomeWhere()
output = codecs.open('file', 'a')
# spawn threads
for i in range(0, 5):
t = PathThread(pathqueue)
t.setDaemon(True)
t.start()
# add paths to queue
for path in paths:
pathqueue.put(path)
# wait for queue to get empty
pathqueue.join()
Run Code Online (Sandbox Code Playgroud) 我见过这样的例子:
for name in os.listdir(u'somedir') :
Run Code Online (Sandbox Code Playgroud)
我的问题是我将somedir作为变量,所以如何附加'u'字面值?
就像是
for name in ops.listdir(u+somedir)
Run Code Online (Sandbox Code Playgroud)
?
我有一个URL列表,我需要获取其中的内容.URL具有特殊字符,因此需要进行编码.我使用Commons HtpClient来获取内容.
我用的时候:
GetMethod get = new GetMethod(url);
Run Code Online (Sandbox Code Playgroud)
我得到一个"无效的"非法转义字符"例外.当我使用时
GetMethod get = new GetMethod();
get.setURI(new URI(url.toString(), false, "UTF-8"));
Run Code Online (Sandbox Code Playgroud)
我试图获取页面时得到404,因为空间被转向%2520而不仅仅是%20.
我已经看过很多关于这个问题的帖子,他们中的大多数建议逐个部分地构建URI.问题是它是一个给定的URL列表,而不是我可以手动处理的URL.
解决这个问题的任何其他方案?
谢谢.
我在Windows Server 2008 R2上运行IIS 7.5.
我在404: file not found浏览"/ bin"文件夹时遇到错误.我知道这是微软的安全政策.
编辑:
应该指出,我没有安全问题.我运行IIS以便在专用网络中进行直接浏览.最终我需要对它执行爬网和索引.问题是由于404错误,未抓取"/ bin"和"/ AppConfig"下的页面.
我只需要一个解决这个问题的方法.同样,这里没有安全问题.