只是在这方面寻求一些帮助。我尝试了一些不同的东西,我很困惑。我正在尝试检查目录中是否存在文件,如果存在,那么我想重命名添加- Copy
到文件名。然后它应该再次检查是否存在冲突,如果没有冲突,它应该移动文件。听起来很简单,但它根本不起作用。由于我无法从String
to转换DirectoryInfo
,我必须声明多个变量,而且感觉不对。我能做些什么来解决这个问题?
Dim fileExt As String = ""
Dim oldFileName As String = file.FullName
Dim newFileName As String = oldFileName
Dim newFileLocation = Environment.GetSpecialFolder(Environment.SpecialFolder.MyPictures) + "\" + file.Name
While FileIO.FileSystem.FileExists(newFileLocation) 'While File exists in new directory
'Add copy to filename
fileExt = fileType.Replace("*", "")
newFileName = newFileName.Remove(newFileName.LastIndexOf("."), (newFileName.Length - newFileName.LastIndexOf(".")))
newFileName += " - Copy"
newFileName += fileExt
'Rename file
FileSystem.Rename(oldFileName, newFileName)
'Declare a new DirInf variable because I can't use a string to set one
Dim newFile As New DirectoryInfo(newFileName)
'Move the new file to
newFile.MoveTo("C:\Users\" + Environ("USERNAME") + "\Pictures\")
ProgressBar.Value += 1
End While