2014-07-22 123 views
0

我有另一个问题,非常类似于 Batch Scripting Moving files with timestamp但我有问题。批处理脚本移动和重命名文件

我有一个文件系统C:\ Test \ Baseline - 在Baseline文件夹下我有许多文件夹,范围从1到10+,这些都是图像文件。我想将这些文件夹内的所有图像复制到仅基于-not tasty.jpg文件的文件夹中,但删除-not tasty.jpg部分。

要地理解这一点这里有一个例子:
C:\Test\Baseline: apple.jpg,orange.jpg,watermellow.jpg,strawberry.jpg,eggs.jpg
C:\Test\Baseline\07-14-14:苹果-tasty.jpg,苹果,不好吃。 JPG,水果,tasty.jpg,水果,不tasty.jpg
C:\Test\Baseline\07-16-14:樱桃tasty.jpg,樱桃不tasty.jpg,橙tasty.jpg,橙不tasty.jpg

那么到底当我运行这个批处理脚本时,它应该将文件从07-14-14 apple-not tasty.jpg和fruits-not tasty.jpg重命名为没有-not tasty.jpg - > apple.jpg和fruits.jpg移动/复制到它的页面的arent目录C:\Test\Baseline并在必要时覆盖 - 还拿樱桃不tasty.jpg,橙不tasty.jpg - > cherry.jpg,orange.jpg移动/复制到C:\Test\Baseline

所以我们留下了
C:\Test\Baseline: apple.jpg,orange.jpg,watermellow.jpg,strawberry.jpg,eggs.jpg,fruits.jpg,cherry.jpg

我希望你能理解这一点。任何帮助将不胜感激。谢谢!

回答

1

希望这会为你工作 -

@echo OFF 

cd D:\test\baseline 

for /f "delims=" %%i in ('dir /s /b "*-not tasty.*"') do copy /y "%%~fi" d:\test\baseline\* >nul 2>&1 

for /f "delims=" %%i in ('dir /b "*-not tasty.*"') do CALL :rename "%%i" 
goto :EOF 

:rename 
set filename=%1 
set newfilename=%filename:-not tasty=% 
ren %filename% %newfilename% >nul 2>&1 
if %errorlevel% EQU 1 del %newfilename% & ren %filename% %newfilename% 

:EOF 

干杯, 摹

+0

哎gbabu,这工作!但它也会发出这个错误信息 '找不到D:\ test \ baseline \ -not tasty命令的语法不正确,但它确实有效。是否有一个小的修复这个/?谢谢 –

+0

啊。在第二个for循环之后忘了在“goto:EOF”之前跳出一个换行符。现在应该可以。 – gbabu

+0

GREATT !!有用!谢谢@gbabu!你还可以帮助我与这个其他问题http://stackoverflow.com/questions/24563087/batch-scripting-moving-files-with-timestamp/24575806?noredirect=1#comment38674569_24575806它是类似的大多数已完成,但我只需要删除-tasty并移动文件.... –