windows 下,要将 train2017/
、val2017/
两个目录下的图片并入一个目录 images/
,用 mklink
创建软链接[1]可以不用额外空间。
win10 也可以写 .sh 脚本用 ln -s
,但效果似乎同 copy?因为用 ln -s
得出的 images/
是有空间占用的,而用 mklink
是 0 bytes。
Code
@echo off
setlocal enabledelayedexpansion
cls
set SRC=G:\dataset\COCO\2017
set DEST=G:\dataset\COCO-stuff\images
if not exist %DEST% (
mkdir %DEST%
)
set n_dir=0
for /d %%d in (train2017 val2017) do (
set "src=%SRC%\%%d"
echo --- !src! ---
set n_image=0
for %%f in (!src!\*.*) do (
REM `n`: 文件名, `x`: 后缀名
REM echo %%~nxf
set "src_img=!src!\%%~nxf"
REM echo !src_img!
set "dest_img=%DEST%\%%~nxf"
REM echo !dest_img!
REM 屏蔽 mklink 的输出
mklink !dest_img! !src_img! > nul 2>&1
REM 每 1000 张提示一下
set /A n_image += 1
set /A r = !n_image! %% 1000
if !r! EQU 0 (
echo !n_image!
)
)
set /A n_dir += 1
)
echo #dir: !n_dir!
References
- windows软链接
- bat文件循环、字符串
- BAT脚本之判断文件是否存在
-
Create list or arrays in Windows Batch,数组
-
Batch Script - Arrays,数组
-
Arrays, linked lists and other data structures in cmd.exe (batch) script,数组
-
for,截文件名
-
bat批处理 if 命令示例详解,if、比较运算
-
Exiting out of a FOR loop in a batch file?,break
-
How to break inner loop in nested loop batch script,break
-
“continue” equivalent command in nested loop in Windows Batch,continue
-
batch script “continue” in loop?,continue
-
Batch Script - Arithmetic operators,四则运算、取模
-
Suppress command line output,屏蔽命令输出