如何获取目录字符串的结尾
How to get the end of a directory string
目的是移动指定文件夹中的文件,如果日期距今天至少有一天,则它们所在的文件夹。我在理论上找不到功能 FirstIndexOf 类似于 LastIndexOf 我想在 Dim 文件名中对文件路径的开头进行子串,以获得文件的名称并将其解析为日期类型。出于动态原因,我不想删除 35 个字符,但我不确定还能做什么。 VS2005.NET 2.0
Sub CopytoArchive(ByVal mydirpath As String)
'Dim mydirpath As String = "C:\UTResults\"
'C:\UTResults\Press3\sv70206655\data07012015.txt is an example of txtFileList
'12345678901234567890123456789012345
Dim txtFileList As String() = Directory.GetFiles(mydirpath, "*.txt", SearchOption.AllDirectories) 'Search all files in the given path with .txt type
For Each txtName As String In txtFileList 'C:\UTResults\Press3\sv70206655\data07012015.txt 'is an example of txtFileList
Dim pressname As String = txtName.Substring(0, txtName.LastIndexOf("\")) 'C:\UTResults\Press3\sv70206655 'take out the file extension
pressname = pressname.Substring(0, pressname.LastIndexOf("\")) 'C:\UTResults\Press3 'take out the folder after the press folder
pressname = pressname.Remove(0, 13) 'Press3 'for a clean "PRESS" look
Dim folderexists As String = "C:\writetest\" + pressname
Dim filename = txtName.Substring(txtName.LastIndexOf("."))
filename = filename.Remove(0, 35)
Dim datestring = DateTime.ParseExact(filename, "MMddyyyy", Nothing)
If datestring < Now.AddDays(-1) Then
My.Computer.FileSystem.CreateDirectory(folderexists)
My.Computer.FileSystem.MoveFile(txtName, folderexists + "\" + "data" + filename + ".txt")
End If
Next
End Sub
Dim filename = Path.GetFileName(txtName)
目的是移动指定文件夹中的文件,如果日期距今天至少有一天,则它们所在的文件夹。我在理论上找不到功能 FirstIndexOf 类似于 LastIndexOf 我想在 Dim 文件名中对文件路径的开头进行子串,以获得文件的名称并将其解析为日期类型。出于动态原因,我不想删除 35 个字符,但我不确定还能做什么。 VS2005.NET 2.0
Sub CopytoArchive(ByVal mydirpath As String)
'Dim mydirpath As String = "C:\UTResults\"
'C:\UTResults\Press3\sv70206655\data07012015.txt is an example of txtFileList
'12345678901234567890123456789012345
Dim txtFileList As String() = Directory.GetFiles(mydirpath, "*.txt", SearchOption.AllDirectories) 'Search all files in the given path with .txt type
For Each txtName As String In txtFileList 'C:\UTResults\Press3\sv70206655\data07012015.txt 'is an example of txtFileList
Dim pressname As String = txtName.Substring(0, txtName.LastIndexOf("\")) 'C:\UTResults\Press3\sv70206655 'take out the file extension
pressname = pressname.Substring(0, pressname.LastIndexOf("\")) 'C:\UTResults\Press3 'take out the folder after the press folder
pressname = pressname.Remove(0, 13) 'Press3 'for a clean "PRESS" look
Dim folderexists As String = "C:\writetest\" + pressname
Dim filename = txtName.Substring(txtName.LastIndexOf("."))
filename = filename.Remove(0, 35)
Dim datestring = DateTime.ParseExact(filename, "MMddyyyy", Nothing)
If datestring < Now.AddDays(-1) Then
My.Computer.FileSystem.CreateDirectory(folderexists)
My.Computer.FileSystem.MoveFile(txtName, folderexists + "\" + "data" + filename + ".txt")
End If
Next
End Sub
Dim filename = Path.GetFileName(txtName)