注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

闻新而动

双核动力

 
 
 

日志

 
 
 
 

文件(夹)搜索引擎  

2008-05-31 11:51:41|  分类: 电脑技术 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

        公司加工中心,线切割有几年下来的程序,放在一指定文件夹下,由于量大,每次寻找时非常费时,所以萌生了开发程序来查找的念头。经过酝酿终于在不久前完成(当然还有点小问题)。

       先来看看界面

文件(夹)搜索引擎 - sokiho - 闻新而动

用法:在MOLD CODE输入相应关键字,MADE DATE中指定年份,然后可能找出所有合适的文件夹。

解决方案:

       首先要解决的是如何查找文件或文件,在网上找了一圈,发现有用API的,有做函数或子程序的,反正一看就很长,但这都不是我想要的,后来在一个很小的论坛里发现了网友介绍Dir[(Pathname[,attributes])] 函数的用法。这正是我所要的。

      DIR()函数可能测试指定路径下的文件夹或文件是否存在,并且支持通配符(?和*)。

      DIR()只返回第一个符合条件的记录,假如想继续查找下一个符合条件的记录就用一个不带参数的DIR()。

       为了能实现整个目录的查找,所以先测试一下目录下目录或文件数,用个FOR 循环就可以解决了。

    用同样的方法,再实现子目录的查找。

     这样软件就完成了。

以下为所有代码:

''2008/5/22 NC Files search engineg完整版发行.
''已知问题,调用NC Vierer 及秀丸时,假如listpart 中指定是文件的话无法调用.
''5/30 功能完善

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal Cx As Long, ByVal Cy _
As Long, ByVal wFlags As Long) As Long
Public strPath1, strPath2 As String

Private Sub Check1_Click()

End Sub

Private Sub Checktop_Click()
If Checktop.Value = 1 Then
 SetOnTop 1
 Else
 SetOnTop 0
  End If
End Sub

Private Sub CmdClear_Click(Index As Integer)
TextMoldcode.Text = ""
ListMold.Clear
Listpart.Clear
ComboYear.ListIndex = 0
Label3.Caption = "Folder(s):"
Label4.Caption = "Folder(s):"

End Sub

Private Sub CmdCut_Click()
Dim stPath As String
stPath = "C:\Program Files\FANUC\CUT MONITOR\BIN\CUTPROG.EXE"
Shell (stPath), vbNormalFocus

End Sub

Private Sub cmdST_Click(Index As Integer)
Dim N, J, P As Integer

Select Case cmdST(Index).Index
Case 0
strPath2 = "MC\SMC-18M\"

Case 1
strPath2 = "MC\FV85A\"

Case 2
strPath2 = "SPACENC\"

Case 3
strPath2 = "Wc\WE-"

Case Else
strPath2 = ""
End Select
'MsgBox (Option1(Index).Index & strPath2)
strPath = strPath1 + strPath2 + ComboYear.Text + "\*" + TextMoldcode.Text + "*"

Debug.Print strPath
ListMold.Clear


               
               
If TextMoldcode.Text <> "" Then  'not input


'Folder COUNT
                N = 0
                sName = Dir(strPath, vbDirectory)
                'sName = strPath
                Do Until sName = ""
                N = N + 1
                sName = Dir()
                Loop
                'Debug.Print N


For P = 1 To N

    'Search type
    If ListMold.ListCount = 0 Then
    bp = Dir(strPath, vbDirectory)
    Else
    bp = Dir()
    End If

 

 'For J = 1 To 100 Step N / 20
    ProgressBar1.Value = 100 / N * P
 'Next J

   
'If bp <> "" Then
ListMold.AddItem bp
'Else
'listmold.AddItem "**** Nothing ****"
'End If

Next P

Label3.Caption = "Folder(s):" & ListMold.ListCount

Else


TextMoldcode.SetFocus

'No input open the defult
Select Case cmdST(Index).Index
Case 0
strPath2 = "MC\SMC-18M\"
Case 1
strPath2 = "MC\FV85A\"
Case 2
strPath2 = "SPACENC\"
Case 3
strPath2 = "Wc\WE-"
Case Else
strPath2 = ""
End Select
Shell ("explorer " & strPath1 + strPath2 + ComboYear.Text), 1

End If

ProgressBar1.Value = 0

End Sub

 

Private Sub ComDrill_Click()
Shell ("explorer ftp://DNC:PCDNC@192.168.0.15/"), 1

End Sub

Private Sub ComEdit_Click()
Shell ("C:\DNC3\SCDEDIT.EXE"), vbNormalFocus
End Sub

Private Sub ComG5X_Click()
Shell ("explorer " + strPath1 + "xy"), vbNormalFocus

End Sub

Private Sub ComHidemaru_Click()
Dim PNam As String, Ppath As String
'  CommonDialog1.MaxFileSize = 32700
'  CommonDialog1.Filter = "(All files *.*)|*.*"
'  CommonDialog1.ShowOpen
'  PNam = CommonDialog1.FileName
'  'Ppath = CurDir & "\"
'  'PNam = Right$(PNam, Len(PNam) - Len(Ppath) - 1)
'  Debug.Print PNam, Ppath
strPath = strPath1 + strPath2 + ComboYear.Text + "\" + ListMold.Text + "\" + Listpart.Text + "\"

Shell ("C:\Program Files\Hidemaru\Hidemaru.exe " & strPath), vbNormalFocus
'Shell ("C:\Program Files\Hidemaru\Hidemaru.exe " & strPath1), vbNormalFocus

End Sub

Private Sub Command1_Click()
If MsgBox("Exit Nc Files Search Engine?", vbQuestion + vbYesNo, "Warning") = vbYes Then
End
End If
End Sub

 

Private Sub ComView_Click()
Dim PNam As String, Ppath As String
'  CommonDialog1.MaxFileSize = 32700
'  CommonDialog1.Filter = "(Camcore *.PTP)|*.PTP|(Space-E *.NT)|*.NT|(Camcore EX *.NC)|*.NC|(All files)|*.*"
'  CommonDialog1.ShowOpen
'  PNam = CommonDialog1.FileName
  'Ppath = CurDir & "\"
  'PNam = Right$(PNam, Len(PNam) - Len(Ppath) - 1)
'  Debug.Print PNam, Ppath
'Shell ("C:\Program Files\NcViewer\NcViewer.exe " & PNam), vbNormalFocus

strPath = strPath1 + strPath2 + ComboYear.Text + "\" + ListMold.Text + "\" + Listpart.Text + "\"

Shell ("C:\Program Files\NcViewer\NcViewer.exe " & strPath), vbNormalFocus

End Sub

Private Sub Form_Load()

'Link button is enable
strPathcut = "C:\Program Files\FANUC\CUT MONITOR\BIN\CUTPROG.EXE"
strPathHidemaru = "C:\Program Files\Hidemaru\Hidemaru.exe"
'strPathHidemaru = "\\192.168.0.101\database\Hidemaru\Hidemaru.exe"

strPathSCDEDIT = "C:\DNC3\SCDEDIT.EXE"
strPathg5X = "\\192.168.0.101\ncdata\xy"
strPathNC = "C:\Program Files\NcViewer\NcViewer.exe"
'strPathNC = "\\192.168.0.101\database\NcViewer\NcViewer.exe"


If Dir(strPathg5X, vbDirectory) <> "" Then
ComG5X.Enabled = True
Else
ComG5X.Enabled = False
End If

If Dir(strPathSCDEDIT, vbDirectory) <> "" Then
ComEdit.Enabled = True
Else
ComEdit.Enabled = False
End If


If Dir(strPathNC, vbDirectory) <> "" Then
ComView.Enabled = True
Else
ComView.Enabled = False
End If

If Dir(strPathHidemaru, vbDirectory) <> "" Then
ComHidemaru.Enabled = True
Else
ComHidemaru.Enabled = False
End If

If Dir(strPathcut, vbDirectory) <> "" Then
Cmdcut.Enabled = True
Else
Cmdcut.Enabled = False
End If

'fill in year
For I = Year(Now()) To 2004 Step -1
ComboYear.AddItem I
'i = i + 1
Next I
ComboYear.ListIndex = 0

'set the server path
strPath1 = "\\server\ncdata\"

'Always on top sw
    If Checktop.Value = 1 Then
     SetOnTop 1
     Else
    SetOnTop 0
      End If
 
'PC name
StatusBar1.Panels(1) = Environ("Computername")
 
ListMold.Clear
Listpart.Clear
 
 
End Sub


Private Sub Listmold_Click()
Dim strSub As String
strSub = strPath1 + strPath2 + ComboYear.Text + "\" + ListMold.Text + "\*"
         Listpart.Clear

'Folder COUNT
                N = 0
                sName = Dir(strSub, vbDirectory)
                'sName = strPath
                Do Until sName = ""
                N = N + 1
                sName = Dir()
                Loop
                'Debug.Print N


    For P = 1 To N
    'Search type
    If Listpart.ListCount = 0 Then
    bp = Dir(strSub, vbDirectory)
    Else
    bp = Dir()
    End If

 

 'Progress....
    ProgressBar1.Value = 100 / N * P


   
'fill in list
Listpart.AddItem bp


Next P

Label4.Caption = "Folder(s):" & Listpart.ListCount

 

ProgressBar1.Value = 0

End Sub

Private Sub listmold_DblClick()
Dim strPath As String


strPath = strPath1 + strPath2 + ComboYear.Text + "\" + ListMold.Text

Debug.Print strPath
Shell ("explorer " + strPath), vbNormalFocus

End Sub

Private Sub Listpart_DblClick()
Dim strPath As String

strPath = strPath1 + strPath2 + ComboYear.Text + "\" + ListMold.Text + "\" + Listpart.Text

Debug.Print strPath
Shell ("explorer " + strPath), vbNormalFocus
End Sub

 

Public Sub SetOnTop(ByVal IsOnTop As Integer)
'always on top
Dim rtn As Long
    If IsOnTop = 1 Then
        rtn = SetWindowPos(NCengine.hwnd, -1, 0, 0, 0, 0, 3)
    Else
        rtn = SetWindowPos(NCengine.hwnd, -2, 0, 0, 0, 0, 3)
    End If
End Sub


Private Sub TextMoldcode_DblClick()
CmdClear_Click (0)
End Sub

 

  评论这张
 
阅读(557)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017