VBS或CMD文件根据文件名模式匹配将文件移动到文件夹 [英] VBS or CMD file to move files into folders based on file name pattern matching
问题描述
寻找一些指导...
我有一个目录,定期接收文件,其名称包含以下信息:
I have a directory that regular receives files whos names contain the following info:
showname-episode-segment.mov
showname-episode-segment.mov
我正在寻找一种方法来将这些文件移动到现有的目录,以showname部分命名文件名。如果文件存在,没有第一个连字符分隔符,应该跳过。
I'm looking for a method to move these files into directories that exist, named after the showname portion of the filename. In the event that a file exists that does not have that first hyphen delimiter it should be skipped. And in the event that a new show is introduced and the corresponding folder does not exist, it would get created.
任何帮助都是值得赞赏的
Any help is appreciated
推荐答案
VBScript可能是最简单的。
VBScript would probably be easiest. Here's a few snippets of how to do everything you'll need.
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
' create a new folder
If Not fso.FolderExists(folderPath) Then
Set newfolder = fso.CreateFolder(folderPath)
End If
' move a file
If fso.FileExists(filePathAndName) Then
fso.MoveFile filePathAndName, folderPath
End If
' check file name
Set folder = fso.GetFolder(folderPath)
Set files = folder.Files
For each file In files
If InStr(file.Name, "-") > 0 Then
'the file name has a "-" in it
End If
Next
这篇关于VBS或CMD文件根据文件名模式匹配将文件移动到文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!