-3
我有一個包含大量圖片的文件夾。我需要根據用戶的輸入複製該文件夾中的圖片並將其複製到新文件夾中:根據用戶的輸入在文件夾中搜索文件,將該文件複製到新文件夾
- 用戶輸入輸入。
- 代碼需要根據輸入搜索文件夾中的圖片。
- 如果找到,則圖片將移至新文件夾/另一個文件夾。
我該怎麼做?
我有一個包含大量圖片的文件夾。我需要根據用戶的輸入複製該文件夾中的圖片並將其複製到新文件夾中:根據用戶的輸入在文件夾中搜索文件,將該文件複製到新文件夾
我該怎麼做?
這是如何做到這一點的一個例子。我不知道你的「用戶輸入」是什麼,所以我只是做了一個假設。酌情糾正。
Sub CopySomeFiles()
Dim FSO, sourceFolder, currentFile, filesInSourceFolder
Dim strSourceFolderPath As String
Dim strDestinationFolderPath As String
Dim strUserInput As String
Set FSO = CreateObject("Scripting.FileSystemObject")
' Figure out which file to copy from where to where
strUserInput = InputBox("Please enter name of file to copy.")
strSourceFolderPath = "C:\MySourceFolder"
strDestinationFolderPath = "C:\MyDestinationFolder"
Set sourceFolder = FSO.GetFolder(strSourceFolderPath)
Set filesInSourceFolder = sourceFolder.Files
' Look at all files in source folder. If name matches,
' copy to destination folder.
For Each currentFile In filesInSourceFolder
If currentFile.Name = strUserInput Then
currentFile.Copy (FSO.BuildPath(strDestinationFolderPath, _
currentFile.Name))
End If
Next
End Sub