PDA

Показать полную графическую версию : error variable used without being declared


sattva
18-01-2011, 21:00
Помогите разобраться, почему возникает эта ошибка: "error variable used without being declared"
Скрипт должен записать в INI-файл MySetupWin7Installer.ini" в секцию "ListImage" все найденые файлы в $Drive & '\' & $tag


Global $tag='Wim'
$var = DriveGetDrive( "ALL" ); Определяем количества и имена всех дисков в системе
If NOT @error Then
For $i = 1 to $var[0]
If FileExists($var[$i]& '\' & $tag) Then
$Drive=$var[$i]; Ищем имя диска который содержит папку "Wim"
EndIf
Next
EndIf


#Include <File.au3>
#Include <Array.au3>
$FileList=_FileListToArray($Drive & '\' & $tag,"*",1)
If @Error=4 Then
MsgBox (0,"","Файлы отсутсвуют в $Drive & '\' & $tag")
Exit
EndIf

;Вносим изменения в INI-файл
dim $n=0
For $i = 1 to $FileList[0]
$n=$n + 1
If FileExists("x:\MySetupWin7Installer.ini") Then
IniWrite ( "x:\MySetupWin7Installer.ini", "ListImage", $n, $Drive & '\' & $tag & '\' & $FileList[$i])
EndIf
Next

sattva
18-01-2011, 21:35
разобрался: в корне диска отсутствовала искомая директория "Wim"
как установить условие, если данная директория не найдена, то завершить работу скрипта.

madmasles
18-01-2011, 21:37
sattva,
Попробуйте так:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <File.au3>

$sDir = 'Wim'
$sIniFile = @ScriptDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptdir) & '\MySetupWin7Installer.ini'
$sSection = 'ListImage'
$q = 0

$aDrives = DriveGetDrive (http://www.autoitscript.com/autoit3/docs/functions/DriveGetDrive.htm)('ALL')
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(16, 'Error', 'Error')
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)

For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aDrives[0]
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) FileExists (http://www.autoitscript.com/autoit3/docs/functions/FileExists.htm)($aDrives[$i] & '\' & $sDir) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$aFiles = _FileListToArray (http://dundats.mvps.org/help/html/libfunctions/_filelisttoarray.htm)($aDrives[$i] & '\' & $sDir, "*", 1)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $j = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aFiles[0]
$q += 1
IniWrite (http://www.autoitscript.com/autoit3/docs/functions/IniWrite.htm)($sIniFile, $sSection, $q, $aDrives[$i] & '\' & $sDir & '\' & $aFiles[$j])
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)

Creat0R
19-01-2011, 00:39
sattva
Предупреждение за нарушение правил форума, пункт 2.7 (http://forum.oszone.net/rules.html#2.7) и пункт 3.19 (http://forum.oszone.net/rules.html#3.19):

2.7: В заголовке темы обязательно обозначайте название предмета, которого касается вопрос, а в теле сообщения максимально подробно опишите проблему (приведите аппаратную/программную конфигурацию, а также изложите ситуацию, в которой возникает проблема)...
Подробнее о принципах создания тем читайте в этом документе (http://forum.oszone.net/faq.php?faq=vb_read_and_post#faq_thread) и Правилах форумов.

3.19: Запрещается... Создавать темы, имеющие неинформативные или состоящие из заглавных букв заголовки (например, "Помогите!", "HELP!", "У меня проблема"). Такие темы будут закрыты или перенесены в Тест-форум. Если вы хотите вернуть перенесенную тему обратно, пока ее не закрыли в Тест-форуме, измените ее заголовок на осмысленный (http://forum.oszone.net/faq.php?faq=vb_board_usage#faq_rename_thread) и напишите об этом в теме.

Переименуйте пожалуйста тему (Как переименовать свою тему? (http://forum.oszone.net/faq.php?faq=vb_board_usage#faq_rename_thread)).




© OSzone.net 2001-2012