您好我的编码朋友。
很抱歉问这个问题,但我想可能会更快问一个人是否有这样的脚本。
我有大约2000多个音频mp3文件的文件记录在我所在的广播电台,我想根据他们记录的日期日期将它们放入文件夹。 (是的,我现在已经修改了录音以便从现在开始正确地执行此操作,但这与我一直在做的事情相关:https://stephenmonro.wordpress.com/2015/05/22/setting-up-an-audio-logger/)
我拥有的文件是这样的:(YYYYMMDD_HH00
)
logs\20150424_0300.mp3
logs\20150424_0400.mp3
logs\20150424_0500.mp3
etc.
我想要的是这样的:
\logs\8 digit date\filename with the same 8 digit date.mp3
实际
\logs\20150424\20150424_0300.mp3
\logs\20150424\20150424_0400.mp3
\logs\20150424\20150424_0500.mp3
etc.
这是我的伪代码,我已经制作了,但是由于时间紧迫而且没有时间来猜测,我只是想知道是否有人知道如何快速完成。
.VBS文件是我的首选语言。
Do
Read a filenames first 8 characters {left(8, filename)} (the date)
If not exist, create a folder called that first 8 characters
Move that file into the folder name
Loop (until all files are moved to the right locations)
答案 0 :(得分:2)
您的伪代码看起来像我。假设logs
文件夹中的每个文件都一致地命名,以下是使用FileSystemObject
库完成的方法:
Const LOGS_FOLDER = "c:\logs"
Dim objFSO, objFile, strDate, strSub
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFile In objFSO.GetFolder(LOGS_FOLDER).Files
strDate = Left(objFile.Name, 8)
strSub = objFSO.BuildPath(LOGS_FOLDER, strDate)
' Create the folder if it doesn't already exist...
If Not objFSO.FolderExists(strSub) Then objFSO.CreateFolder strSub
' Move the file into its proper folder. Use "\" to indicate dest is folder...
objFile.Move strSub & "\"
Next