我已經解決了我的問題......我還沒有解決的是如果.bat檔案位于父檔案夾中并且它應該適用于所有子檔案夾,我該怎么做?
現在,只有當.bat檔案與檔案位于同一檔案夾中時,它才會創建檔案夾。如果檔案位于子檔案夾內,則無法創建檔案夾。
我所擁有的是:
這個的檔案名.bat是:
組織.bat
@echo off
for %%i in (*) do (
if not "%%~ni" == "organize" (
md "%%~ni" && move "%%~i" "%%~ni"
)
)
我現在是怎么做的:
- 我將
.bat檔案與檔案一起放在一個檔案夾中 - 當我點擊它時,它會根據該檔案夾中的檔案創建一個檔案夾
- 它還將移動同名檔案夾中的每個檔案
我需要的:
- 將
.bat檔案放在主檔案夾中,其中包含許多包含檔案的子檔案夾 - 單擊它以執行與上述相同的任務
如果我的解釋令人困惑,請道歉......我希望它仍然可以理解。
先感謝您!
uj5u.com熱心網友回復:
您的嘗試非常接近作業,但要注意使用簡單方法而不檢查每個細節的皺紋,所以,從這里開始:-
@echo off & Title %~n0
REM I recommend using cd /d "%~dp0" to ensure you start from the known cmd file folder location not some system folder
cd /D "%~dp0"
REM add the /R switch to run through subdirs
for /R %%i in (*) do (
REM replace organize to %~n0 so as to aid renaming by other users
if not "%%~DPni" == "%~DPn0" (
REM to allow for nested paths we need a fuller DP location for N (check it works exactly as desired then remove the echos)
echo md "%%~DPni" && echo move "%%~i" "%%~DPni"
)
)
小心帶有雙 .dot.s 的檔案,例如 cmd.exe.lnk,因此請先檢查那些回聲
md "C:\Users\me\Favorites\Links\cmd.exe"
move "C:\Users\me\Favorites\Links\cmd.exe.lnk" "C:\Users\me\Favorites\Links\cmd.exe"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/312619.html
