![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-01 19:02 |
48,037 topics / 350,122 posts / today 2 new / 48,249 members |
| DOS批处理 & 脚本技术(批处理室) » [Original] Converting Chinese resource files for Struts and JSF framework internationalization |
| Printable Version 1,115 / 2 |
| Floor1 wentimao | Posted 2006-06-07 20:07 |
| 初级用户 Posts 27 Credits 110 | |
|
Over the past few days I posted on the forum to ask questions, and based on everyone's help I made this batch file. It is mainly used for converting Chinese resource files for Struts and JSF framework internationalization. Please take a look and tell me what still needs to be corrected or optimized. Also, please don't keep replying in my earlier threads anymore.
willsort, look at these lines: if exist "%~f1\" goto error if not exist "%~f1" goto error Originally this was to prevent the case where the input parameter is a folder, but like I said, if in the current folder there is both a file named aa and a folder named aa, then won't these two lines fail? The method you suggested was: for /f "usebackq" in ("%~f1") do ...)2>nul What does this method mean? Does it try to operate on it no matter whether it is a file or a directory, and if it's wrong then just suppress it? Is that what it means? I don't quite understand, and hope you can explain it. The discussions related to this topic are as follows: How to get the full path of a file? http://www.cn-dos.net/forum/viewthread.php?tid=20996 How to determine whether a parameter is a file or a directory http://www.cn-dos.net/forum/viewthread.php?tid=20999 How to read the paths in the PATH environment variable one by one? http://www.cn-dos.net/forum/viewthread.php?tid=21008 How to search the whole disk for a file and add its path to the environment variable http://www.cn-dos.net/forum/viewthread.php?tid=21013 How to change the value of %1 from the command line in a batch file? http://www.cn-dos.net/forum/viewthread.php?tid=21014 How not to display an error prompt when dir does not find the file http://www.cn-dos.net/forum/viewthread.php?tid=21021 [ Last edited by willsort on 2006-6-14 at 17:45 ] |
|
| Floor2 willsort | Posted 2006-06-14 18:21 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re wentimao:
Very sorry! This original topic by you was overlooked for so long! I have now done a little cleanup on the topic, changed the title, highlighted it with red underlining, and awarded 16 credits. As for checking the existence of a file and folder with the same name, I still hold the same view as in related reply [2] above: don't bother with it unless there is really a need to bother with it. As for the later for/f solution I proposed, it is roughly as you said: for /f "usebackq" requires that ("") must contain a filename, otherwise it will be unable to read its text contents and will display an error message, while the following )2>nul can suppress the error message. As for the fact that this solution has some flaws, one known issue is that if the operation after confirming file existence is placed after do, it may be executed multiple times because the file contains multiple lines of text. The improved solution is as follows: for /f "usebackq" %%f in ("%~f1") do set) >nul 2>nul || echo File %~f1 does not exist Re Others: What feels rather strange is that, whether %~f1 exists or not, for /f does not modify %errorlevel%, but the following && or || still work normally. Does this mean that the conditions for && and || do not depend on %errorlevel%? |
|
| Floor3 wentimao | Posted 2006-06-15 07:54 |
| 初级用户 Posts 27 Credits 110 | |
|
I modified that search code using one person's method. This way there is no need to create a temporary file, which feels much more convenient.
set x="sbl" for %%i in (native2ascii.exe) do if exist %%~$PATH:i set x=%%~$PATH:i if not %x% == "sbl" goto :pass echo. echo The path variable does not include the path to native2ascii.exe. This program will now automatically search all drives echo for the directory containing native2ascii. This process may take some time, please wait.... echo. echo. echo Searching...... echo. echo. for %%i in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( (for /f "delims=" %%p in ('dir /a /b /s %%i:\native2ascii.exe') do ( echo Found %%p set path=%path%;%%~dpp&&goto :pass )) 2>nul ) echo. echo native2ascii.exe does not exist on your computer, conversion cannot be completed. echo. goto :end |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |