2015-08-19 35 views
1

你好我的编码朋友的文件夹。将文件移动到基​​于文件名的第一个X字符(VBS)

不好意思问这个,但我认为它可能是更快地问,如果有人有这样躺在身边的脚本。

我有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

一种能解决你的问题后,你可以尝试,如果你喜欢这个脚本:如何在Windows中播放所有歌曲球员在vbscript? 这里有两个版本,一个在后台,另一个与wmpalyer.exe最小化播放播放列表! http://stackoverflow.com/questions/29327153/how-to-play-all-songs-in-windows-player-in-vbscript?answertab=active#tab-top – Hackoo

+0

嗨@Hackoo,而文件是mp3,我只是需要他们组织。不管怎么说,还是要谢谢你。 –

回答

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 
+0

天才。这不是每天都有007帮助我。感谢队友,奇妙地工作。 :) –

相关问题