Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用用户输入搜索文件夹中的文件,然后创建文件副本_Asp.net_.net_Vb.net - Fatal编程技术网

Asp.net 使用用户输入搜索文件夹中的文件,然后创建文件副本

Asp.net 使用用户输入搜索文件夹中的文件,然后创建文件副本,asp.net,.net,vb.net,Asp.net,.net,Vb.net,我正在尝试创建一个简单的程序,该程序将使用用户输入在特定文件夹中搜索图像(如果图像存在),然后将该图像的副本创建到另一个文件夹。用户可能没有全名,例如,图像名称可能是iStock-454565767,用户可以在没有iStock的情况下输入数字 我们使用数千张已购买的istock照片,并将其保存在一个文件中,这使得搜索特定图像变得困难,尤其是当我们可能同时需要几张照片时 我有以下代码: Private Sub btnSearch\u单击(发送者作为对象,e作为事件参数)处理btnSearch。单击

我正在尝试创建一个简单的程序,该程序将使用用户输入在特定文件夹中搜索图像(如果图像存在),然后将该图像的副本创建到另一个文件夹。用户可能没有全名,例如,图像名称可能是
iStock-454565767
,用户可以在没有
iStock
的情况下输入数字

我们使用数千张已购买的istock照片,并将其保存在一个文件中,这使得搜索特定图像变得困难,尤其是当我们可能同时需要几张照片时

我有以下代码:

Private Sub btnSearch\u单击(发送者作为对象,e作为事件参数)处理btnSearch。单击
Dim FSO、sourceFolder、currentFile、FileInsourceFolder
将strSourceFolderPath设置为字符串
Dim strDestinationFolderPath作为字符串
作为字符串的Dim strUserInput
FSO=CreateObject(“Scripting.FileSystemObject”)
strUserInput=txtSearch.Text
strSourceFolderPath=“C:\Users\D41071023\Desktop\Photo数据库”
strDestinationFolderPath=“C:\Users\D41071023\Desktop\test”
sourceFolder=FSO.GetFolder(strSourceFolderPath)
filesInSourceFolder=sourceFolder.Files
对于FileInsourceFolder中的每个currentFile
如果currentFile.Name=strUserInput,则
currentFile.Copy(FSO.BuildPath(strDestinationFolderPath,
currentFile.Name)
如果结束
下一个
端接头

当我点击“搜索”时,什么也没发生。没有创建任何文件,甚至没有错误。此外,我还想添加一个在创建文件时弹出的消息框,或一条让用户知道未找到图像的消息。

如果我理解正确,这是您应该具备的功能:

Dim sourceFolderPath=“此处的源文件夹路径”
Dim fileNumber=“此处的文件编号”
Dim sourceFilePath=Directory.GetFiles(sourceFolderPath,$“iStock-{fileNumber}.png”).SingleOrDefault()
如果sourceFilePath不是空的,那么
Dim destinationFolderPath=“此处的目标文件夹路径”
Dim sourceFileName=Path.GetFileName(sourceFilePath)
Dim destinationFilePath=Path.Combine(destinationFolderPath,sourceFileName)
File.Copy(sourceFilePath、destinationFilePath)
如果结束
据我所知

Dim sourceFolderPath=“source Folderpath here””Folderpath不带空格
Dim fileNumber=“此处的文件编号”
Dim sourceFilePath=Directory.GetFiles(sourceFolderPath,$“iStock-{fileNumber}.png”).FirstOrDefault()
如果不是Nothing(sourceFilePath),则
Dim destinationFolderPath=“destination Folderpath here””不带空格的Folderpath
Dim sourceFileName=Path.GetFileName(sourceFilePath)
Dim destinationFilePath=Path.Combine(destinationFolderPath,sourceFileName)
File.Copy(sourceFilePath、destinationFilePath)
MsgBox(“文件”&“iStock-{fileNumber}.png”&“found.”,MsgBoxStyle.OkOnly)
其他的
MsgBox(“未找到文件…”,MsgBoxStyle.OkOnly+MsgBoxStyle.Information)
如果结束

如果currentFile.Name.Contains(strUserInput)您应该执行类似于
的操作,顺便说一句,请使用
IO.Filesystem
类。如果要使用VB.NET,请使用它
Directory.GetFiles
File.Copy
是您所需要的全部。为什么用户没有包含“iStock-”部分这一事实意味着您的代码不能?