China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 20:30
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Ask for Advice]Batch Renaming of PAK Exported Files View 1,683 Replies 6
Original Poster Posted 2009-11-22 15:15 ·  中国 甘肃 张掖 中移铁通
新手上路
Credits 9
Posts 7
Joined 2007-08-16 20:29
18-year member
UID 95270
Gender Male
Status Offline
The export format of PAK files in the game is:
The CRC32 checksum of the file.out
For example:
ui\0147E5A6.out

There is a file storing the original file name list.txt, (due to the post reason, it is not clear, between each column in each row is TAB separated, and between the time items (2009-6-30 15:22:1) is space separated) The format is:
TotalFile:768 PakTime:2009-11-11 11:13:40 PakTimeSave:4afa2be4 CRC:3f91d323
Index ID Time FileName Size InPakSize ComprFlag CRC
0 6bf9d 2009-6-30 15:22:1 \ui\script\window\playerstate.lua 5108 1834 4 4aecede2
1 5e0d8d 2008-10-24 10:1:21 \ui\001a\window\blogviewplayer.ini 9241 1806 4 71579ab8
2 c8f97d 2009-9-23 17:50:16 \ui\001a\worldmap\npcsetting\1622.txt 109 104 4 c461871a

Now we need to rename the source file to the target file.
The file name of the source file is the value of the last column of list.txt, which is CRC, with the suffix.out.
The target file is the value of the fourth column, Filename, in list.txt.
For example:
c461871a.out is renamed to \ui\001a\worldmap\npcsetting\1622.txt

I'm a newbie and tried to write it with FOR myself but didn't succeed.
Please ask the experts, and use batch processing to rename, thank you!

=======================
Current directory: D:\UI
list.txt
The ninth column is the source file name (note that the source file name here does not have the suffix:.out)
The fifth column is the target file name

【Idea】Use FOR, extract the ninth column (source file name without suffix, 4aecede2) in the list.txt file, modify it to the complete source file name (for example: D:\UI\4aecede2.out), and use Xcopy to rename it to the target file name pointed to by the fifth column (for example: D:\UI\ui\script\window\playerstate.lua)

=======================




Test record
I did it myself, for reference:
for /f "skip=2 tokens=5,9" %i in(list.txt) do command

skip=2 Skip the first two lines
tokens=5 Take the target file path
tokens=9 Take the source file name
command Execute the command, rename the source file name to the target file name xcopy %i.out %j
I'll go test it...
Error: %i gets the file name, without the suffix, how to make it %i.out like the full file name?

2009-11-23 20:30 modification test:
Batch processing:
for /f "skip=2 tokens=5,9" %%i in (list.txt) do set var=%%j set de=%%i

Display:
set var=47f384bb
set de=\script\event\zhongqiu_jieri\200809\item\canghaiyueming.lua

Currently, the parameters can be obtained, but the var variable (for example: 47f384bb) cannot be changed to the source file name (for example: 47f384bb.out)

2009-11-24 2:30 modification test:
Current directory:D:\UI
Command line operation:D:\UI>bat-out.bat out
Content of batch processing file bat-out.bat:
@setlocal ENABLEDELAYEDEXPANSION
@cd
@set pth=!cd!
@set suf=%1
for /f "skip=2 tokens=5,9" %%i in (list.txt) do call out.bat %pth% %%j %suf% %%i
@endlocal

Content of batch processing file out.bat:
xcopy /f %~dp1%~n2%~x3 %~f4

Command line echo content:
D:\UI>call out.bat D:\UI\script
ddecb8c2 out \script\event\jieri\200812_xmas\item\xmas_giftbox.lua

D:\UI>xcopy /f D:\UI\ddecb8c2 D:\UI\scriptevent\jieri\200812_xmas\item\xmas_giftbox.lua
File not found - ddecb8c2
0 file(s) copied

Analysis:
When CALL batch processing, the suf environment variable value is correct, but when passed to out.bat, that is: the passed parameter %3 does not become %~x3, that is, it becomes the suffix of the file, so xcopy cannot find the file.
Hey, I can't solve it myself, please help me, thank you!

2009-11-26 21:16 modification test:
Content of bat-out.bat:
@setlocal ENABLEDELAYEDEXPANSION
@cd
@set pth=!cd!
@set suf=%1

for /f "skip=2 tokens=5,9" %%i in (list.txt) do @call set src="%pth%\%%j.%%1" &&@call set des="%pth%%%i" &&@call out.bat %%src%% %%des%%
@endlocal


Content of out.bat:
xcopy /f %~dpnx1 %~dpnx2

Command line operation: bat-out.bat out
Screen echo:
D:\UI>xcopy /f D:\UI\script\78F8C5ED.out D:\UI\script\script\task\target\usertrackinfo.lua

Target D:\UI\script\script\task\target\usertrackinfo.lua is a file name
Or a directory name
(F = file, D = directory)? f
D:\U-Disk\TMP\JXSJ_Pak\out\script\78F8C5ED.out -> D:\U-Disk\TMP\JXSJ_Pak\out\scr
ipt\script\task\target\usertrackinfo.lua
1 file(s) copied

Analysis:
There is a problem with the parameter passing of out.bat.
By modifying out.bat to echo parameters:
@echo bgin
@echo %~1
@echo ,
@echo %~2
The screen displays correct passing, but now the format of the parameter variable is incorrect. That is, the %1, %2 passed parameters cannot be set to the correct source file and target file for Xcopy.
Official explanation:
Description
Default value for destination

If destination is omitted, the xcopy command copies files to the current directory.
Specify whether destination is a file or directory

If destination does not contain an existing directory and does not end with a backslash (\), the xcopy command displays a prompt message in the following format:

Does destination specify a file name
or directory name on the target
(F = file, D = directory)?

Press F if you want to copy one or more files to a file. Press D if you want to copy one or more files to a directory.

The /i switch can be used to avoid this prompt. If the /i switch is used, xcopy assumes the destination is a directory if the source is one or more files or directories.

[ Last edited by apareon on 2009-11-28 at 13:51 ]
Floor 2 Posted 2009-11-25 13:33 ·  中国 甘肃 张掖 中移铁通
新手上路
Credits 9
Posts 7
Joined 2007-08-16 20:29
18-year member
UID 95270
Gender Male
Status Offline
No one answers? Is it because I'm a newbie?
Floor 3 Posted 2009-11-25 14:09 ·  中国 北京 阿里云BGP服务器
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
Now we need to rename the source file to the target file.
The filename of the source file is the last column of list.txt, with the suffix .out.
The target file is the Filename corresponding to the last column value of list.txt.

The source file and the target file are both the last column. Are you kidding me!!!???
Floor 4 Posted 2009-11-26 18:59 ·  中国 甘肃 张掖 中移铁通
新手上路
Credits 9
Posts 7
Joined 2007-08-16 20:29
18-year member
UID 95270
Gender Male
Status Offline
Originally posted by moniuming at 2009-11-25 02:09 PM:

Both the source file and the target file are in the last column. Are you kidding me!!!???


Sorry, it was a typo, and it has been corrected.
Floor 5 Posted 2009-11-26 23:48 ·  中国 北京 阿里云BGP服务器
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
Hey, no expert is here to answer for you, so this newbie will give it a try. Actually, you're not a newbie anymore...

@echo off
:: Should be run in the d:\ui directory...
for /f "skip=2 tokens=5,9" %%a in ('type list.txt') do (
echo.copy /y "%%b.out" "d:\%%a"
rem If the display meets the requirements, just remove the "echo." above
)
pause
Floor 6 Posted 2009-11-28 13:41 ·  中国 甘肃 张掖 中移铁通
新手上路
Credits 9
Posts 7
Joined 2007-08-16 20:29
18-year member
UID 95270
Gender Male
Status Offline
Reply to post 5:

First of all, thank you for your help!

弱弱的 ask a question: The English parentheses "(" and ")" after do in the FOR I wrote are giving an error. I don't know how you can use the parentheses?

It ran but prompted an error:
The system cannot find the specified path.
0 files copied.

I remember that the target file path specified by copy must exist, that is, the target directory cannot be newly created

I replaced it with xcopy /y, and it prompted that it cannot recognize whether the target is a directory or a file. The error prompt is as follows:
The target D:\UI\script\event\huihuangguo\huihuangguo_C.lua
Is it a file name
Or a directory name
(F = file, D = directory)?

[ Last edited by apareon on 2009-11-28 at 13:49 ]
Floor 7 Posted 2009-11-29 18:02 ·  中国 广东 广州 番禺区 广州海之光通讯技术有限公司
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
It seems there is no this parameter, add "echo f|"...
@echo off
::It should be run in the d:\ui directory...
for /f "skip=2 tokens=5,9" %%a in ('type list.txt') do (
echo f|xcopy /f /e /y "edkdi.txt" "d:\%%a"
)
pause


[ Last edited by moniuming on 2009-11-29 at 18:44 ]
Forum Jump: