批处理脚本移动时间戳文件 [英] Batch Scripting Moving files with timestamp

查看:187
本文介绍了批处理脚本移动时间戳文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我有一个文件系统C:\\测试\\基线。在文件夹的BaseLine我有很多文件夹,它可能是一个文件夹或文件夹15,在这些文件夹的图片文件。我想所有的图像由内这些文件夹中复制不包括基线文件夹到另一个位置,即C:\\测试\\在每个图像的最终实现与日期标记的图像为2014年3月7日

So basically I have a file system C:\Test\BaseLine. Under BaseLine folder I have many folders, it could be one folder or 15 folders, in those folders are image files. I want to copy all the images from INSIDE those folder NOT including BaseLine folder into another location namely C:\Test\Achieve Images with Date stamp as 03-07-2014 at the end of each image.

例如我得文件夹系统是这样的:结果
的baseline - 1.JPG,2.JPG结果
- > [文件夹123] - 3.JPG,4.JPG结果
- > [文件夹321] - 5.JPG,6.JPG结果

For example i'll have folder system like this:
BaseLine - 1.jpg, 2.jpg
->[Folder 123] - 3.jpg, 4.jpg
->[Folder 321] - 5.jpg, 6.jpg

在我的脚本结束时,我应该有我的C:\\测试\\获得具有这些图片像这样的图片:结果
实现图片 - 3_03-07-2014.jpg,4_03-07-2014.jpg,5_03-07-2014.jpg,6_03-07-2014.jpg

At the end of my script i should have my C:\Test\Achieve images having these images like so:
Achieve Images - 3_03-07-2014.jpg, 4_03-07-2014.jpg, 5_03-07-2014.jpg, 6_03-07-2014.jpg

注意它不包含任何基线主文件夹的图片。

Notice how it does not include any of the BaseLine main folder images.

到目前为止,我有这样的脚本:

So far i have a script like this:

CD / DC:\\测试\\的BaseLine \\
@SET DATE_FOLDER =%日期:7,2〜% - %日期:〜4.2% - %日期:10.4〜%
SETACHIEVE_DIR = C:\\测试\\主实现
对/天%%一个在(*)做XCOPY%% A \\ *。*%ACHIEVE_DIR%\\/ S / H / E / K / F / C / Y
结果
PS:这个code与[用户] foxidrive的帮助。再次感谢好友的其他问题,我有!

cd /d "C:\Test\BaseLine\" @SET DATE_FOLDER=%date:~7,2%-%date:~4,2%-%date:~10,4% SET "ACHIEVE_DIR=C:\Test\Master Achieve" for /d %%a in ("*") do xcopy "%%a\*.*" "%ACHIEVE_DIR%\" /s/h/e/k/f/c/y
PS: This code was with the help of [user]foxidrive. Thanks again buddy for the other problem i had!!

这工作,但时间戳不追加到每个图像文件的结尾
谢谢!

This works but does not append the timestamp to the end of each image files Thanks!

推荐答案

您无法用 XCOPY 做,而是因为你已经在评论中提到的,这将重命名文件在复制之前。

You cannot do it with xcopy but as you've outlined in the comments, this renames the files before copying.

这code的前四行会给你在XP专业版和更高的可靠性YY MM DD YYYY HH分秒变量。

The first four lines of this code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher.

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

SET "DATE_FOLDER=%YYYY%%MM%%DD%"

cd /d "C:\Test\BaseLine\"
SET "ACHIEVE_DIR=C:\Test\Master Achieve" 
md "%ACHIEVE_DIR%" 2>nul

for /d %%a in (*) do (
for /r %%b in ("%%a\*.jpg") do ren "%%~b" "%%~nb - %DATE_FOLDER%%%~xb"
xcopy "%%a\*.jpg" "%ACHIEVE_DIR%\" /s/h/e/k/f/c/y
)
pause

tasty.jpg 文件复制到%ACHIEVE_DIR% 修改 code到所有 *动code>和日期戳记它们,然后取出在 C:\\测试\\的BaseLine \\ 所有剩余的文件,但留下里面的文件 C:\\测试\\的BaseLine \\ 完整

Edit code to move all *-tasty.jpg files to the %ACHIEVE_DIR% and datestamp them, then remove the original containing folders under C:\Test\BaseLine\ with all remaining files but leaving the files inside C:\Test\BaseLine\ intact.

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

SET "DATE_FOLDER=%YYYY%%MM%%DD%"

cd /d "C:\Test\BaseLine\"
SET "ACHIEVE_DIR=C:\Test\Master Achieve" 
md "%ACHIEVE_DIR%" 2>nul

for /d %%a in (*) do (
for /r %%b in ("%%a\*-tasty.jpg") do move "%%~b" "%ACHIEVE_DIR%\%%~nb - %DATE_FOLDER%%%~xb"
rd /s /q "%%a"
)
pause

这篇关于批处理脚本移动时间戳文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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