如何将索引文件添加到所有子目录 [英] How to add an index file to all subdirectories

查看:86
本文介绍了如何将索引文件添加到所有子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我做了一些有点愚蠢的事情,我希望有一些善良的灵魂可以帮助我。


有一段代码经过并在子目录中创建了大量的子目录,这很好。最初我忘了在每个目录中创建一个index.html文件,以防止在没有人登录的情况下查看其文件夹和文件。我现在已修复它,但是有一堆没有此文件的目录。


是否有一些代码,如果我指定顶级目录,将通过并添加索引文件?


我有代码添加文件。我一直坚持要让代码遍历子目录中的所有子目录。这就是我到目前为止所拥有的:

Hello all,

I''ve done something a bit stupid and am hoping some kind soul out there can help me out.

There''s a piece of code that goes through and creates a high number of subdirectories within subdirectories, which is fine. Initially I forgot to create an index.html file in each directory to prevent viewing of its folders and files without people being logged in. I''ve fixed it now, but there are a whole heap of directories without this file.

Is there some piece of code which, if I specify the top directory, will go through and add the index file?

I have the code the add the file. I''m stuck on getting the code to go through all subdirectories within subdirectories etc. Here''s what I have so far:

展开 | 选择 | Wrap | 行号

推荐答案

现在就是保护目录的方法。 index.html文件只是给他们看的东西。如果我真的想看看目录中的内容,我就可以访问它了。


如果您正在运行Apache,或者不将目录放在站点目录下,请使用.htaccess文件,将它们放在其他位置。




Dan
This is now how you protect your directories. An index.html file just gives them something to see. If I really wanted to see what''s in the directory, I''d have no problem accessing it.

use a .htaccess file if your running Apache, or don''t put the directories under the site directory, put them elsewhere.




Dan


嘿Dan,


感谢您的回复。

@ dlite922


重点是,如果某人找不到用户的目录,然后他们将这条路径输入浏览器的地址栏,他们只会看到一个空白文件,而不是文件夹和文件列表。当然在那里有index.html文件可以实现这个目标吗?


你能否扩展一下如何访问目录中的文件。

Hey Dan,

Thanks for the reply.

@dlite922
The point is that if someone works out the user''s directory, and they enter that path into the address bar of the browser, all they''ll see is a blank file, not the listing of folders and files. Surely having the index.html file in there will accomplish this?

Can you please expand on how you could access the files in a directory.


如果运行Apache,或者不将目录放在站点目录下,则使用.htaccess文件,将它们放在别处。 Dan
use a .htaccess file if your running Apache, or don''t put the directories under the site directory, put them elsewhere. Dan



我认为这个解决方案不会起作用,因为子目录中的子目录可能存在子目录。

无论如何,我仍然对如何对特定目录中的每个子文件夹执行某些操作感兴趣,无论是添加索引文件还是执行其他操作。

I don''t think this solution will work as it''s possible for there to be subdirectories within subdirectories within subdirectories.

Anyway, I''m still interested in how to do something to every subfolder in a particular directory, whether it''s adding an index file or doing something else.


@beary


有一些履带式软件可以做到这一点。我没有使用它,但如果我猜或知道我正在寻找的文件名,一种方法是直接访问该文件。


我只是说如果那里有敏感数据你需要保护,这不是一种方法。如果黑客拥有这些文件并不重要,那么这可能适用于普通用户。我仍然不明白你为什么要在公共网站上公开不公开的文件夹。


您可以通过.htaccess控制访问:

RewriteRule ^包含/this.file.does.not.exist

RewriteRule ^ errors /this.file.does.not.exist



我给你的URL确实显示你有一个递归可以使用遍历目录树。




Dan
@beary
There are some crawler type software that do it. I have not used it, but one method would be direct access to the file if I guess or know the file name I''m looking for.

I''m just saying if there is sensitive data in there that you need protected, this is not a way to do it. If it doesn''t really matter if a hacker has the files, then this could work for the average user. I still don''t understand why you would want folders that are not public be on a public site.

You can control access via a .htaccess:

RewriteRule ^includes /this.file.does.not.exist
RewriteRule ^errors /this.file.does.not.exist



The URL i gave you does show you have a recursion can be used to traverse a directory tree.





Dan


这篇关于如何将索引文件添加到所有子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆