如果您发布您正在工作的 .bat 代码,这将非常有帮助。如果没有这个,我只能说,根据您链接到的代码,您可能需要添加以下内容:
首先在顶部附近添加:
setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
然后(我没有重写旧代码,但最后的 2 行应该是你需要的):
FOR %F IN (C:\temp\source\*.*) DO IF !SrcCount! LSS %SrcMax% (
SET /A SrcCount += 1
ECHO !SrcCount! COPY %F C:\temp\output
COPY %F C:\temp\output
rem ** Here are the new lines **
SET FNAME=%%~nF
XCOPY /s "C:\game\store\0.1.2\sky\stuff\!FNAME:~3!" "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
)
更新 1
rem @ECHO OFF
setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
SET SrcCount=0
SET SrcMax=15
IF NOT EXIST C:\game\mod\0.1.2\map\data md C:\game\mod\0.1.2\map\data
IF NOT EXIST C:\game\mod\0.1.2\sky\stuff md C:\game\mod\0.1.2\sky\stuff
FOR %%F IN (C:\game\mod\store\XMLs\*.*) DO IF !SrcCount! LSS %SrcMax% (
SET /A SrcCount += 1
ECHO !SrcCount! COPY %%F C:\game\mod\0.1.2\map\data\
COPY %%F C:\game\mod\0.1.2\map\data\
SET FNAME=%%~nF
ECHO XCOPY /s "C:\game\mod\store\models\!FNAME:~3!" "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
XCOPY /s "C:\game\mod\store\models\!FNAME:~3!" "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
)
这是我之前的文件系统:
C:\game>dir /s /b
C:\game\mod
C:\game\mod\store
C:\game\mod\store\models
C:\game\mod\store\XMLs
C:\game\mod\store\models\01_aaa
C:\game\mod\store\models\01_aaa\test.txt
C:\game\mod\store\XMLs\Map01_aaa.xml
这是之后:
C:\game>dir /s /b
C:\game\mod
C:\game\mod\0.1.2
C:\game\mod\store
C:\game\mod\0.1.2\map
C:\game\mod\0.1.2\sky
C:\game\mod\0.1.2\map\data
C:\game\mod\0.1.2\map\data\Map01_aaa.xml
C:\game\mod\0.1.2\sky\stuff
C:\game\mod\0.1.2\sky\stuff\01_aaa
C:\game\mod\0.1.2\sky\stuff\01_aaa\test.txt
C:\game\mod\store\models
C:\game\mod\store\XMLs
C:\game\mod\store\models\01_aaa
C:\game\mod\store\models\01_aaa\test.txt
C:\game\mod\store\XMLs\Map01_aaa.xml
这是输出:
D:\bat>docopy.bat
D:\bat>rem @ECHO OFF
D:\bat>setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
D:\bat>SET SrcCount=0
D:\bat>SET SrcMax=15
D:\bat>IF NOT EXIST C:\game\mod\0.1.2\map\data md C:\game\mod\0.1.2\map\data
D:\bat>IF NOT EXIST C:\game\mod\0.1.2\sky\stuff md C:\game\mod\0.1.2\sky\stuff
D:\bat>FOR %F IN (C:\game\mod\store\XMLs\*.*) DO IF !SrcCount! LSS 15 (
SET /A SrcCount += 1
ECHO !SrcCount! COPY %F C:\game\mod\0.1.2\map\data\
COPY %F C:\game\mod\0.1.2\map\data\
SET FNAME=%~nF
ECHO XCOPY /s "C:\game\mod\store\models\!FNAME:~3!" "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
XCOPY /s "C:\game\mod\store\models\!FNAME:~3!" "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
)
D:\bat>IF !SrcCount! LSS 15 (
SET /A SrcCount += 1
ECHO !SrcCount! COPY C:\game\mod\store\XMLs\Map01_aaa.xml C:\game\mod\0.1.2\map\data\
COPY C:\game\mod\store\XMLs\Map01_aaa.xml C:\game\mod\0.1.2\map\data\
SET FNAME=Map01_aaa
ECHO XCOPY /s "C:\game\mod\store\models\!FNAME:~3!" "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
XCOPY /s "C:\game\mod\store\models\!FNAME:~3!" "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
)
1 COPY C:\game\mod\store\XMLs\Map01_aaa.xml C:\game\mod\0.1.2\map\data\
1 file(s) copied.
XCOPY /s "C:\game\mod\store\models\01_aaa" "C:\game\mod\0.1.2\sky\stuff\01_aaa\"
C:\game\mod\store\models\01_aaa\test.txt
1 File(s) copied
D:\bat>c:
C:\game>dir /s /b
该代码正在我的机器上运行。我不知道怎样才能提供更多帮助。
更新 2
!FNAME:~3! 是什么意思?意味着,特别是~3?
这是一个子字符串操作,它删除了前三个字符。
我们从类似Map01_aaa.xml
%%F 的内容开始:
SET FNAME=%%~nF
仅提取文件名Map01_aaa
. 然后:
!FNAME:~3!
删除 的前 3 个字符01_aaa
,您指出这是所需的目录名称。
C:\>set test=abcdef
c:\>echo !test:~3!
def
set /?
May also specify substrings for an expansion.
%PATH:~10,5%
would expand the PATH environment variable, and then use only the 5
characters that begin at the 11th (offset 10) character of the expanded
result.
更新 3
我不好,文件夹名称实际上是 01_aaa_map 等等。
然后改变:
XCOPY /s "C:\game\mod\store\models\!FNAME:~3!" "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
至:
XCOPY /s "C:\game\mod\store\models\!FNAME:~3!_map" "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!_map\"