2009-10-06 21 views
0

我想出來一個程序,它可以通過從文本文件中讀取路徑來打開文件夾。 打開時,代碼將檢查文件夾內是否有文件。對於第一個文件,執行一些調用函數,它將繼續執行,直到文件夾中可用的最後一個文件。如何選擇文件夾中的文件?

例如,如果文件夾A的內容是3個文件1st.doc,2nd.txt,3rd.pdf,它會對每個文件做一個操作,直到最後一個文件退出。

感謝

我需要如何實現它的理想,任何語言的引用或例子也有很大幫助。

林在基本編碼是:

;open textfile 
$dir = "C:\Documents and Settings\admin\My Documents\AutoItCodes\" 
$file = FileOpen($dir & "Setting.txt", 0) 
If $file = -1 Then 
    MsgBox(0, "Error", "Unable to open file.") 
    Exit 
EndIf 

$source = FileReadLine($file,1) 
$dest = FileReadLine($file,2) 
$pass = FileReadLine($file,3) 
FileClose($file) 

;check files available in the folder $source 
$search = FileFindFirstFile($source & "*.*") 

; Check if the search was successful 
If $search = -1 Then 
    MsgBox(0, "Error", "No files/directories matched the search pattern") 
    Exit 
EndIf 

;Check for the first file and display in message box 
;***I belived it all start here!!*** 

While 1 
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop 
    MsgBox(4096, "File:", $file) 
WEnd 

; Close the search handle 
FileClose($search) 

問題的修復程序。謝謝。但仍然ND另一個問題u'all幫助

Dim objShell: Set objShell = CreateObject("Shell.Application") 
Dim objFolder : Set objFolder = objShell.Namespace(source) 
Dim colItems: Set colItems = objFolder.Items 
Dim i 
For i = 0 to colItems.Count - 1 
    colItems.Item(i).InvokeVerbEx("Encrypt") 
    'do my execution 
    call moveToFolder() 
Next 

我有這個功能moveToFolder(),將所有的*的.pac移動到不同的文件夾中。

  • 錯誤:操作在函數調用之前停止。所述權限被拒絕
  • 如何添加移動文件並覆蓋相同名稱是否存在?

Sub moveToDest() 
dim newfolder 
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject") 
If Not objFSO.FolderExists(dest) Then 
    newfolder = objFSO.CreateFolder (dest) 
    WScript.Echo "A new folder '" & newfolder & "' has been created" 
End If 
objFSO.MoveFile source & "*.pac" , dest, true 
End Sub 

回答

0

你的標籤說VBScript中,所以這裏有幾點注意事項:

Option Explicit 

Const ForReading = 1 
Dim a, fs, f, fldr, i, s 

Set fs = CreateObject("Scripting.FileSystemObject") 

Set f = fs.OpenTextFile("C:\Docs\fileList.txt", ForReading) 

a = Split(f.ReadAll,vbCrLf) 

f.Close 

If fs.FolderExists(a(0)) Then 

    Set fldr = fs.GetFolder(a(0)) 
    i = fldr.Files.Count 

    If i>0 Then 
     For Each f In fldr.Files 
      s=vbCrLf & f.Name 
     Next 

     MsgBox s 
    Else 
     MsgBox a(0) & " does not have any files." 
    End If 
Else 
    MsgBox a(0) & " does not exists." 
End If 
+0

比方說,我想在文件保持並在郵件中做一些調用的函數,而不是調用顯示盒子,我該怎麼做? – user147685 2009-10-07 01:51:29

相關問題