本帖最后由 bailong360 于 2016-3-19 13:09 编辑
result.txt的格式就不能好看点吗- 1>1/* :
- @echo off
- setlocal enabledelayedexpansion
- for /f "tokens=2" %%i in ('findstr "\*" result.txt^|^|echo no') do (
- if "%%i"=="no" (
- echo 无GPT磁盘
- pause>nul
- exit
- )
- set /a n+=1,choice=%%i
- set GPT=!GPT!,%%i
- )
- if %n% gtr 1 set /p choice=请选择一个磁盘(%GPT:~1%?):
- cscript -nologo -e:jscript "%~f0" "%choice%"
- exit
- */
- var FSO = new ActiveXObject('Scripting.FileSystemObject');
- var Argu = WScript.arguments;
- var Disk = Argu.item(0);
- var DiskReg = new RegExp('磁盘 ' + Disk + ' 现在(.|[\\r\\n])*磁盘 ' + (Disk * 1 + 1), '');
- var zone = FSO.OpenTextFile('result.txt', 1).ReadAll().match(DiskReg)[0].match(/\d+(?= 主要)/g);
- var ZoneNum = zone[zone.length - 1];
-
- Edit('diskpart.ini', 2, 9, Disk);
- Edit('diskpart.ini', 4, 9, ZoneNum);
- Edit('id.ini', 2, 9, Disk);
- Edit('id.ini', 4, 8, ZoneNum * 1 + 2);
- Edit('id.ini', 7, 7, ZoneNum * 1 + 1);
-
- function Edit(FileName, Line, Old, New) {
- var NewFile = '';
- var file = FSO.OpenTextFile(FileName, 1);
- var LineCount = 0;
- while (!file.AtEndOfStream) {
- var str = file.ReadLine();
- if (++LineCount == Line) {
- str = str.replace(Old, New);
- }
- NewFile = NewFile + str + '\r\n';
- }
- file.Close();
- file = FSO.OpenTextFile(FileName, 2);
- file.Write(NewFile);
- file.Close();
- }
复制代码
|