以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]删除目录  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=65633)

--  作者:liujywwy
--  发布时间:2015/3/19 16:04:00
--  [求助]删除目录
当子目录里面的文件为空,那就把当前的子目录删除。

Dim ftp As New FtpClient
Dim dls As List(of String)
ftp.Host="192.168.1.35"
ftp.Account = "tester"
ftp.Password = "tester"
Dim lj As String = "/待用户现场确认版本_产线禁止使用/2015/" & Tables("临时版本跟踪表").current("临时版本编号") & "(" & Tables("临时版本跟踪表").current("客户") & "_" & Tables("临时版本跟踪表").current("博达机型") & ")"

dls = ftp.GetDirList("lj")
msgbox(lj)
For Each dl As String In dls
If (lj &  "/" & dl). count<= 1 Then
ftp.DeleteDir(lj &  "/" & dl)
End If    
Next--------------红色的改怎么写,主要是判断子目录里面文件的个数。
ftp.Close
Forms("FTP管理器").close
比如待用户现场确认版本_产线禁止使用\\2015\\11130_2014(TELESTE AB_S2528gx)下面有这么多按照时间建立的子目录。如果某几个子目录下的文件为空,然后自动删除这个子目录。

图片点击可在新窗口打开查看此主题相关图片如下:子目录.png
图片点击可在新窗口打开查看


--  作者:Bin
--  发布时间:2015/3/19 16:06:00
--  
http://www.foxtable.com/help/topics/1410.htm

GetFileList

用于返回FTP服务器指定目录下的全部文件名,以字符串集合的形式返回,语法:

GetFileList(Path)

Path:可选参数,用于指定目录,如果省略,则返回当前目录下的全部文件名。

示例

例如列出photo目录下的所有文件:

Dim ftp1 As New FtpClient
Dim 
fls As List(of String
ftp1.Host=
"196.128.143.28"
ftp1
.Account = "foxuser"
ftp1
.Password = "138238110"
fls = ftp1.GetFileList(
"\\photo")
For Each 
fl As String In fls
    
Output.Show(fl)
Next

还可以使用通配符,例如列出photo目录下的所有jpg文件:

Dim ftp1 As New FtpClient
Dim 
fls As List(of String
ftp1
.Host="196.128.143.28"
ftp1
.Account = "foxuser"
ftp1
.Password = "138238110"
fls = ftp1.GetFileList(
"\\photo\\*.jpg")
For Each 
fl As String In fls
    
Output.Show(fl)
Next

GetDirList

用于返回FTP服务器指定目录下的全部子目录,以字符串集合的形式返回,语法:

GetDirList(Path)

Path:可选参数,用于指定目录,如果省略,则返回当前目录下的全部子目录名。

示例

Dim ftp1 As New FtpClient
Dim
 dls As List(of String
ftp1.Host=
"196.128.143.28"
ftp1.Account = 
"foxuser"
ftp1.Password = 
"138238110"
dls = ftp1.GetDirList(
"\\photo")
For
 Each dl As String In dls
    
Output.Show(dl)
Next


--  作者:有点甜
--  发布时间:2015/3/19 16:08:00
--  

Dim ftp As New FtpClient
Dim dls As List(of String)
ftp.Host="192.168.1.35"
ftp.Account = "tester"
ftp.Password = "tester"
Dim lj As String = "/待用户现场确认版本_产线禁止使用/2015/" & Tables("临时版本跟踪表").current("临时版本编号") & "(" & Tables("临时版本跟踪表").current("客户") & "_" & Tables("临时版本跟踪表").current("博达机型") & ")"


dls = ftp.GetDirList(lj)
msgbox(lj)
For Each dl As String In dls
    If ftp.GetFileList(lj & "/" & dl).Count < 1 Then
        ftp.DeleteDir(lj &  "/" & dl)
    End If
Next
ftp.Close
Forms("FTP管理器").close


--  作者:liujywwy
--  发布时间:2015/3/19 16:38:00
--  
效果不对,并没有删除为空的子目录。
Dim ftp As New FtpClient
Dim dls As List(of String)
ftp.Host="192.168.1.35"
ftp.Account = "tester"
ftp.Password = "tester"
Dim lj As String = "/待用户现场确认版本_产线禁止使用/2015/" & Tables("临时版本跟踪表").current("临时版本编号") & "(" & Tables("临时版本跟踪表").current("客户") & "_" & Tables("临时版本跟踪表").current("博达机型") & ")"


dls = ftp.GetDirList("lj")
msgbox(lj)-------已执行
For Each dl As String In dls
msgbox(dl)---未执行,应该是把dls中的每个元素都列出来才对。
 If ftp.GetFileList(lj & "/" & dl).Count < 2 Then
        ftp.DeleteDir(lj &  "/" & dl)
    End If    --------这个if判断未删除为空的子目录。
Next
ftp.Close
Forms("FTP管理器").close

--  作者:有点甜
--  发布时间:2015/3/19 18:04:00
--  

这句写错了啊

dls = ftp.GetDirList("lj")
 
看3楼

--  作者:liujywwy
--  发布时间:2015/3/19 18:38:00
--  
还是没删除啊。
Dim ftp As New FtpClient
Dim dls As List(of String)
ftp.Host="192.168.1.35"
ftp.Account = "tester"
ftp.Password = "tester"
Dim lj As String = "/待用户现场确认版本_产线禁止使用/2015/" & Tables("临时版本跟踪表").current("临时版本编号") & "(" & Tables("临时版本跟踪表").current("客户") & "_" & Tables("临时版本跟踪表").current("博达机型") & ")"
dls = ftp.GetDirList(lj)
msgbox(lj)
For Each dl As String In dls
    If ftp.GetFileList(lj & "/" & dl).Count < 1 Then
        ftp.DeleteDir(lj &  "/" & dl)
        msgbox(dl)-----弹出的文件夹名称是对的,但却没删除。
    End If
Next

ftp.Close
Forms("FTP管理器").close

--  作者:有点甜
--  发布时间:2015/3/19 19:30:00
--  

ftp.DeleteDir(lj &  "/" & dl, True)

 

DeleteDir

删除FTP上的目录,语法:

DeleteDir(DirName,AnyWay)

DirName:要删除的目录名称。
AnyWay:可选参数,如果设为True,将删除目录下的文件及其子目录,如果省略此参数,则只有此目录为空的时候,才能删除。

如果删除成功,返回True,否则返回False

 

 


--  作者:新福星
--  发布时间:2016/7/9 5:23:00
--  
我也遇到这种情况,用FTP ftp.DeleteDir(mlm, True)    这个命令空目录无法删除!
--  作者:Hyphen
--  发布时间:2016/7/9 9:27:00
--  
测试没有问题。

有时候操作系统就是这样,删除了,目录却还在,这个没有办法的。用的时候判断一下吧