2009-10-06 62 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

相关问题