迭代文件夹批处理

时间:2018-03-06 23:34:33

标签: batch-rename

我对批处理有些新意,我正在尝试批量生成一个程序,将所有文件重命名为数字,但它只是不起作用,我不知道这里有什么问题,我希望有人可以帮我找到它。

import vlc, time

vlc_instance = vlc.Instance()
song         = 'D:\\mozart.mp3'
player = vlc_instance.media_player_new()
media  = vlc_instance.media_new(song)

media.get_mrl()
player.set_media(media)

player.play()
playing = set([1])
time.sleep(1.5) # startup time.
duration = player.get_length() / 1000
mm, ss   = divmod(duration, 60)

print "Current song is : ", song, "Length:", "%02d:%02d" % (mm,ss)

time_left = True

# the while loop checks every x seconds if the song is finished.
while time_left == True:

    song_time = player.get_state()

    print 'song time to go: %s' % song_time

    if song_time not in playing:

        time_left = False

    time.sleep(1) # if 1, then delay is 1 second.

print 'Finished playing your song'

1 个答案:

答案 0 :(得分:0)

这个快速的怎么样?

我提供了一个if条件,以防止批量重命名,以防你将它放在文件所在的同一目录中。 (例如在测试时) 您可能希望根据需要进行更改...

numberize.bat

@ECHO OFF
SetLocal EnableDelayedExpansion

set /a x=0
for %%i in (*) do ( call :doit "%%i" )
goto eof

:doit
    if  /I %1 NEQ "numberize.bat"  (
        set  /a "x=x+1"
        ren %1 %x%
    )
    EXIT /B
:eof

EndLocal