2010-01-08 170 views
1

我有一個包含大約10000個圖像的文件夾,我需要將其中約500個文件複製到另一個文件夾。將文件夾中的文件列表複製到另一個文件夾

如果我創建了我想要複製的文件列表,我怎麼能將這些文件複製到文件中?

思考VBScript或是否有可能徹底的DOS命令如Xcopy使用開關?

感謝,

+0

你是如何創建文件列表?他們是否符合一些簡單的標準? – Tarydon

+0

是的文件列表將在一個文本文件... egimage1.jpg \ n image2.jpg等等......看看下面的答案我想我會很快使用其中之一。 – thegunner

回答

3

假設你有文件的文本文件列表,這裏是一個VBScript

Set objFS=CreateObject("Scripting.FileSystemObject") 
Set objArgs = WScript.Arguments 
strFile = objArgs(0) 
strDestination = objArgs(1) 
Set objFile =objFS.OpenTextFile(strFile) 
Do Until objFile.AtEndOfLine 
    strLine = objFile.ReadLine 
    objfs.CopyFile strLine,strDestination &"\"&strLine 
Loop 

另存爲myscript.vbs和命令行

C:\test>more file 
test1.txt 
test2.txt 

c:\test> cscript //nologo myscript.vbs file c:\destination\directory 

OR如果要批量生產

@echo off 
for /F %%i in (file) do ( copy "%%i" c:\destination ) 

,如果你想根據某種模式移動文件的列表中,只是做

c:\test> copy *pattern*.txt c:\destination 
2

對於在命令行上一次性的,準備filenames.txt,每行一個名稱。然後發出:

for /f %n in (filenames.txt) do copy "%n" "t:\arget\folder" 

VBScript的,你可以實現使用Scripting.FileSystemObject同樣的事情,它的近親(如FileFolder對象),但相比之下,這是更爲複雜。 ghostdog74的答案顯示了一種方法。

相關問題