Что нового

Многофайловое открытие файлов и редактирование их

astati

Новичок
Сообщения
145
Репутация
4
Здравствуйте!
Есть папка в которой есть файлы(допустим 4)
Нужен скрипт который будет открывать файлы, что бы их можно было редактировать и в последствии сохранить. Причем каждый файл в разных вкладках и значение после = из строк, в поле input.
Файлы имеют разширение ".properties".
код чистой формы:
Код:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$GUI = GUICreate("Conf", 258, 297, 189, 136)
GUICtrlCreateTab(0, 20, 249, 265)
$Tab_1 = GUICtrlCreateTabItem("1")
GUICtrlCreateLabel("Some Text", -2, 51, 4, 4)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Input1 = GUICtrlCreateInput("", 128, 66, 73, 22)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Input2 = GUICtrlCreateInput("", 128, 90, 73, 22)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label6 = GUICtrlCreateLabel("Пункт 1 =", 8, 66, 99, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label4 = GUICtrlCreateLabel("Пункт 2 =", 8, 90, 100, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label9 = GUICtrlCreateLabel("Пункт 3 =", 8, 114, 102, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Input3 = GUICtrlCreateInput("", 128, 114, 73, 22)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Tab_2 = GUICtrlCreateTabItem("2")
$Label1 = GUICtrlCreateLabel("Пункт 1 =", 11, 66, 99, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label2 = GUICtrlCreateLabel("Пункт 2 =", 11, 90, 100, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label3 = GUICtrlCreateLabel("Пункт 3 =", 11, 114, 102, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Input4 = GUICtrlCreateInput("", 131, 66, 73, 22)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Input5 = GUICtrlCreateInput("", 131, 90, 73, 22)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Input6 = GUICtrlCreateInput("", 131, 114, 73, 22)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Tab_3 = GUICtrlCreateTabItem("3")
$Label5 = GUICtrlCreateLabel("Пункт 1 =", 7, 60, 99, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label7 = GUICtrlCreateLabel("Пункт 2 =", 7, 84, 100, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label8 = GUICtrlCreateLabel("Пункт 3 =", 7, 108, 102, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Input7 = GUICtrlCreateInput("", 127, 60, 73, 22)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Input8 = GUICtrlCreateInput("", 127, 84, 73, 22)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Input9 = GUICtrlCreateInput("", 127, 108, 73, 22)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$TabSheet1 = GUICtrlCreateTabItem("4")
GUICtrlCreateTabItem("")
$Button1 = GUICtrlCreateButton("SAVE", 176, 8, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
	;$nMsg = GUIGetMsg()
	Switch GUIGetMsg() ;$nMsg
	Case $GUI_EVENT_CLOSE
		If MsgBox(32 + 4, 'Question', 'Вы уверены что хотите выйти?', Default, $Gui) = 6 Then Exit
	Case $Button1
		If MsgBox(32 + 4, 'Question', 'Сохранить файл?', Default, $Gui) = 6 Then
                MsgBox(64, 'Info', 'Сохранено')
		Else
                MsgBox(64, 'Info', 'Настройки не были сохранены')
			EndIf
			Exit
	EndSwitch
WEnd

Содержание(примерное) одного из файлов
Код:
# ================================================================
# Настройка первого пункта
Пункт 1 = 2

# Настройка второго пункта
Пункт 2 = false

# Настройка третьего пункта
Пункт 3 = 3000
P.S. извените не знаю как правильно тему под такое назвать.
P.S.S кидаю архив в котором как все должно быть
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
astati,
Попробуйте так.
Код:
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

$sDir = @ScriptDir & '\config'
$sExt = '.properties'
$iCount = 0

$aTemp = _FileListToArray($sDir, '*' & $sExt, 1)
If @error Then
	MsgBox(16, 'Error', '_FileListToArray')
	Exit
EndIf
Dim $aFilesInfo[$aTemp[0] + 1][3]
For $i = 1 To $aTemp[0]
	$sText = FileRead($sDir & '\' & $aTemp[$i])
	$aText = StringRegExp($sText, '(?m)^([А-ЯЁ].*?)\r?$', 3)
	If Not @error Then
		$iCount += 1
		$aFilesInfo[$iCount][0] = StringReplace($aTemp[$i], $sExt, '')
		$aFilesInfo[$iCount][1] = UBound($aText)
		$aFilesInfo[$iCount][2] = $aText
		If $aFilesInfo[0][1] < $aFilesInfo[$iCount][1] Then $aFilesInfo[0][1] = $aFilesInfo[$iCount][1]
	EndIf
Next
$aTemp = 0
If Not $iCount Then
	MsgBox(16, 'Error', 'Error')
	Exit
EndIf
ReDim $aFilesInfo[$iCount + 1][3]
$aFilesInfo[0][0] = $iCount
$iCount = 0

Dim $aTab[$aFilesInfo[0][0] + 1][4][$aFilesInfo[0][1] + 1] = [[[$aFilesInfo[0][0]]]]

$hGUI = GUICreate('Test', 300, $aFilesInfo[0][1] * 30 + 105)
GUICtrlCreateTab(5, 10, 290, $aFilesInfo[0][1] * 30 + 50)
For $i = 1 To $aTab[0][0][0]
	$aTab[$i][0][0] = $aFilesInfo[$i][0]
	$aTab[$i][1][0] = GUICtrlCreateTabItem($aTab[$i][0][0])
	$aTemp = $aFilesInfo[$i][2]
	$aTab[$i][2][0] = $aFilesInfo[$i][1]
	For $j = 0 To $aFilesInfo[$i][1] - 1
		$aTab[$i][2][$j + 1] = GUICtrlCreateLabel(StringRegExpReplace($aTemp[$j], '=.*$', '') & '= ', _
				15, 53 + $j * 30, 100, 16, $SS_RIGHT)
		$aTab[$i][3][$j + 1] = GUICtrlCreateInput(StringRegExpReplace($aTemp[$j], '^.*=\s', ''), _
				125, 50 + $j * 30, 60, 20, $SS_CENTER)
	Next
	GUICtrlCreateTabItem('')
Next
$nButton = GUICtrlCreateButton('SAVE', 100, $aFilesInfo[0][1] * 30 + 70, 100, 25)
GUISetState()
$aFilesInfo = 0
While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $nButton
			GUISetState(@SW_DISABLE)
			For $i = 1 To $aTab[0][0][0]
				$sText = FileRead($sDir & '\' & $aTab[$i][0][0] & $sExt)
				$aText = StringSplit(StringStripCR($sText), @LF)
				$sText = ''
				For $w = 1 To $aText[0]
					$fYes = True
					For $j = 1 To $aTab[$i][2][0]
						If StringRegExp($aText[$w], '^' & GUICtrlRead($aTab[$i][2][$j])) Then
							$sText &= GUICtrlRead($aTab[$i][2][$j]) & GUICtrlRead($aTab[$i][3][$j]) & @CRLF
							$fYes = False
						EndIf
					Next
					If $fYes Then
						$sText &= $aText[$w] & @CRLF
					EndIf
				Next
				$hFile = FileOpen($sDir & '\' & $aTab[$i][0][0] & $sExt, 2)
				FileWrite($hFile, StringTrimRight($sText, 2))
				FileClose($hFile)
			Next
			GUISetState(@SW_ENABLE)
			MsgBox(64, 'Info', 'Все')
	EndSwitch
WEnd
 
Автор
A

astati

Новичок
Сообщения
145
Репутация
4
Спасибо чувак все работает. Плюсик в профиль :smile: :beer:
P.S. Ща пойду до думывать с увеличением количества полей...
 
Верх