![](/img/trans.png)
[英]How to batch move files in subdirectories down one folder in Windows?
[英]windows Batch script to check if the subdirectories of a folder are not git repositories
我從命令行執行 bat 文件
@echo off
FOR /D %%a IN (*) DO (
for /f "tokens=*" %%g in ('cd %%a ^& dir /a:d ^| find ".git"') do (
if %%g=="" @echo %%ais not a repo
)
)
檢查目錄的某些子文件夾是否不是 git 存儲庫,但是當我執行它時命令行中沒有顯示任何內容。
不幸的是,對於這個問題,我們需要做的是從不執行該任務的代碼中.git
存檔的標准。
for /f
如果沒有找到任何內容(即沒有包含.git
的子目錄),將不會執行do
部分。
所以 - 假設一個目錄有一個子目錄,其名稱包含.git
然后是一個repo
@ECHO OFF
SETLOCAL
rem The following setting for the source directory is a name
rem that I use for testing and deliberately includes spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.
SET "sourcedir=u:\your files"
FOR /d %%b IN ("%sourcedir%\*") DO (
SET "notgit=Y"
FOR /f %%g IN ('dir /ad "%%b" 2^>nul ^| find /i ".git"') DO SET "notgit="
IF DEFINED notgit ECHO %%b is not a repo
IF NOT DEFINED notgit ECHO %%b is a repo
)
GOTO :EOF
將每個目錄查找到%%b
並使用%%b
設置一個標志,假設它不包含.git
子目錄。 查找所有包含.git
的子目錄名稱,如果找到任何此類子目錄,則將notgit
設置為空。
然后根據flag的state上報。
2^>nul
抑制No...found
錯誤報告,而if /i
使find
不區分大小寫
FOR /f %%g IN ('dir /ad "%%b\*.git*" 2^>nul') DO SET "notgit="
可能更好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.