![](/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.