2014-07-22 169 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並移動文件.... –