批处理循环以使用时间戳进行重命名并将文件从一个文件夹移动到另一个文件夹 [英] Batch for loop to rename with timestamp and move files from one folder to another one

查看:161
本文介绍了批处理循环以使用时间戳进行重命名并将文件从一个文件夹移动到另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将zip文件从一个文件夹批量移动到另一个文件夹.我想了解如何完成我的代码,以便将zip文件从一个文件夹移动到另一个重命名文件,并在文件名中添加时间戳.

I am trying to move zip files from one folder to another one with batch. I want to understand how to complete my piece of code in order to move zip files from one folder to another one renaming files, adding to the name of the file the timestamp.

for /f %%a in ('dir /b  \\XXX\XXX\XXX\XXX\XXX\*.zip ^| find /c /v ""') do (

)
EXIT

编辑

在python中,我会这样写:

In python I would have written something like this:

Location = '\\\\XXXX\\XXX\\XXX\\XXX\\XXX\\'
checklist2 = glob.glob(Location + '*.zip')

for filename2 in checklist2:
    NewName = filename2.replace(Location, '')
    NewName = NewName.replace('.ZIP', '')
    shutil.move(filename2, Location + 'Archive\\ZIP Archive\\' + NewName + '_' + time.strftime('%Y%m%d%H%M%S') + '.zip')

推荐答案

看看这是否对您有帮助:

See if you this helps you:

for %%a in (*) do echo %%~na-%%~ta%%~xa

%%~na是文件的名称.
%%~ta是文件的时间戳.
%%~xa是文件扩展名.

%%~na is the name of the file.
%%~ta is the timestamp of the file.
%%~xa is the file extension.

这篇关于批处理循环以使用时间戳进行重命名并将文件从一个文件夹移动到另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆