2016-05-08 59 views
2

以下文件中的所有文件夾是我的嘗試:集FOLDERNAME =文件夾名稱:! =批量重命名含有特定模式

@echo off 
REM Prefix zz_ to folders containing episodes with zz_ 
setlocal enabledelayedexpansion enableextensions 
for /r "G:\itunes\Podcasts\" %%f in (zz_*.mp3) do (
    set N=%%~pf~ 
    set N=!N:\itunes\Podcasts\=! 
    set N=!N:\=! 
if exist %%f ren "g:%%~pf" "zz_!N!" 
) 
pause 

但我收到錯誤消息:該進程無法訪問,因爲它的文件正在被另一個進程使用。 我不是一個程序員,只是削減&粘kinda傢伙,所以謝謝你的任何幫助。

所以,上面的錯誤當然是我試圖緩衝目錄(g:\ itunes \ podcasts)時修改子目錄。所以以下笨重的代碼確實有效,但有一個例外。

@echo off 
setlocal enabledelayedexpansion enableextensions 
REM Prefix zz_ to folders containing episodes with zz_ 
for /r "G:\itunes\Podcasts\" %%f in (zz_*.mp3) do (
    set foldername=%%~pf 
    set foldername=!foldername:~17! 
    set foldername=!foldername:\=! 
    if exist %%f echo if exist %%f ren "g:%%~pf" "zz_!foldername!" >>g:\trash.bat 
) 
call g:\trash.bat 
del g:\trash.bat 

pause 

它不處理包含感嘆號的文件名。有什麼想法嗎?

+0

是否正在使用.mp3文件?因爲那就是那個錯誤信息所暗示的。 – SomethingDark

+2

關閉'echo off',看看你正在做的奇怪的事情。 –

回答

0

下面的工作,但是非常笨重......一件事是,即使在找到第一個zz_podcast之後,它仍然繼續搜索文件夾。在批處理文件中執行批處理文件的想法最終可能會導致我需要轉義字符的其他問題。對於第二批,我需要對下面顯示的百分比符號進行編輯。如果有人能想出一種完全不同的方法,那麼會更好嗎?也許更優雅?

@echo off 
REM Prefix zz_ to folders containing episodes with zz_ 
setlocal DisableDelayedExpansion 
REM The following recurses g:\itunes\podcasts looking for zz_ podcasts 
for /r "G:\itunes\Podcasts\" %%f in (zz_*.mp3) DO (
set "filename=%%f" 
set "filepath=%%~pf" 
set "foldername=%%~pf" 
REM Delayed Expansion needed here for edits to file, path & folder names 
setlocal EnableDelayedExpansion 
set filename2=!filename:%%=%%%%! 
set filepath=!filepath:%%=%%%%! 
set foldername=!foldername:~17! 
set foldername=!foldername:\=! 
set foldername=!foldername:%%=%%%%! 
if exist "!filename!" echo if exist "!filename2!" ren "g:!filepath!" "zz_!foldername!" >>g:\trash.bat 
endlocal 
) 
REM trash.bat has its own issues with escaped characters 
call g:\trash.bat 
del g:\trash.bat 

這是一回事。當我編輯播客標籤時,我經常需要在「上下文」中看到未經編輯的播客,以便決定最佳發展方向。例如,如果一個播客在其標題中有'重播',那麼在刪除它之前我需要確保我有原件。因此,我暫時將播客標記爲zz_,然後打開整個zz_文件夾以查看上下文中的zz_episode「