svatvn Posted June 27, 2012 Posted June 27, 2012 Hi guys, I have a code for batch like this: for %%i in ("%CD%\*.reg") do (start /w regedit /s "%%i") What I want is, that all .reg-files in a folder to be added to the registry, So what would be the code for Autoit? Thanks
BrewManNH Posted June 27, 2012 Posted June 27, 2012 Here's how I'd do it. #include <File.au3> $aFiles = _FileListToArray("C:pathname", "*.reg") ; gets the list of *.reg files in the folder For $I = 1 To $aFiles[0] ; loops through the list of files, the number of them is contained in $aFiles[0] Run("Regedit.exe /S " & "C:pathname" & $aFiles[$I]) ; Run regedit with the /s command on each file in the array Next ; loop to the next one in the array. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
svatvn Posted June 27, 2012 Author Posted June 27, 2012 hi BrewMan, it doesnt work and I also tried to replace C:pathname with @ScriptDir, but it doesnt work either... can you check to code please?
JohnQSmith Posted June 27, 2012 Posted June 27, 2012 C:pathname is where your .REG files are located, not where your script is located (unless your .REG files are in the script folder). You might also try adding a "" after the c:pathname in line 4. Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".
UEZ Posted June 27, 2012 Posted June 27, 2012 The backspace in run command is missing: Run("Regedit.exe /S " & "C:pathname" & $aFiles[$I]) ; Run regedit with the /s command on each file in the array Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
svatvn Posted June 27, 2012 Author Posted June 27, 2012 thx everybody, but the reg-files are in the scriptfolder, how would the code be for that?
DicatoroftheUSA Posted June 27, 2012 Posted June 27, 2012 @ScriptDir Help > contents > "macro reference" Statism is violence, Taxation is theft. Autoit Wiki
svatvn Posted June 27, 2012 Author Posted June 27, 2012 (edited) I tried to replace "C:pathname" with @ScriptDir, but AutoIT's path definition is so complicated ... can you give me the correct code? sorry, I'm newbie in coding Edited June 27, 2012 by svatvn
Moderators JLogan3o13 Posted June 27, 2012 Moderators Posted June 27, 2012 (edited) svatvn, DicatoroftheUSA gave you a reasonable answer, and included a gentle suggestion to actually look in the help file rather than being spoon-fed code you do not understand. If the reg files are in the same directory as your script, you would use @ScriptDir & "" Couple that with BrewManNH's response, you would get: #include <File.au3> $aFiles = _FileListToArray(@ScriptDir, "*.reg") ; gets the list of *.reg files in the folder For $I = 1 To $aFiles[0] ; loops through the list of files, the number of them is contained in $aFiles[0] Run("Regedit.exe /S " & @ScriptDir & "" & $aFiles[$I]) ; Run regedit with the /s command on each file in the array Next ; loop to the next one in the array. Edited June 27, 2012 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
svatvn Posted June 27, 2012 Author Posted June 27, 2012 hi all, the backslash was the problem, it works now, #include <File.au3> $aFiles = _FileListToArray(@ScriptDir&"/", "*.reg") ; gets the list of *.reg files in the folder For $I = 1 To $aFiles[0] ; loops through the list of files, the number of them is contained in $aFiles[0] Run("Regedit.exe /S " & @ScriptDir&"/" & $aFiles[$I]) ; Run regedit with the /s command on each file in the array Next ; loop to the next one in the array. thank you very much for your patience
svatvn Posted June 27, 2012 Author Posted June 27, 2012 (edited) I've got another problem with spaces in the path of the scriptdir I tried to put quotes to "@ScriptDir", but it seems to be wrong. How can I make it work with spaces? sorry for my newbie-questions Edited June 27, 2012 by svatvn
DicatoroftheUSA Posted June 27, 2012 Posted June 27, 2012 (edited) Nest double quotes in single quotes e.g. '"C:documents and settings"' or '"'&@scriptdir&''&$aReg[$x]&'"' Edited June 27, 2012 by DicatoroftheUSA Statism is violence, Taxation is theft. Autoit Wiki
svatvn Posted June 27, 2012 Author Posted June 27, 2012 (edited) sorry, I don' get it may be I'm too stupid for that. What I get are just errors. can you make this code work? #include <File.au3> $aFiles = _FileListToArray('"& @ScriptDir & "/", "*.reg"'') For $I = 1 To $aFiles[0] Run("Regedit.exe /S "''& @ScriptDir & "/" & $aFiles[$I] & '"') Next In batch, it's just this line for %%i in ("%CD%*.reg") do (start /w regedit /s "%%i") why is it so unbelievable complicated in AutoIT? Edited June 27, 2012 by svatvn
DicatoroftheUSA Posted June 27, 2012 Posted June 27, 2012 (edited) #include $sDir=@scriptdir $aFiles = _FileListToArray('"'&$sDir&'"', "*.reg"'') For $I = 1 To $aFiles[0] Run(@comspec" /k Regedit.exe /S" &'"'& $sdir & "" & $aFiles[$I] & '"') consolewrite(@lf&"Regedit.exe /S" &'"'& $sdir & "" & $aFiles[$I] & '"'&@lf) Next In batch, it's just this line for %%i in ("%CD%*.reg") do (start /w regedit /s "%%i") why is it so unbelievable complicated in AutoIT? Complexity can result in a capability, C++ is more complicated than autoit but it can do more, C is more complicated than C++ but ... A hammer is less complex than a batch script, but I am guessing your problem isn't a nail. The funny thing is the complexities of nesting with spaces is the result of bad logic from the origin of the command prompt, and will surface in writing sufficiently complex batch files as well. Edited June 27, 2012 by DicatoroftheUSA Statism is violence, Taxation is theft. Autoit Wiki
svatvn Posted June 27, 2012 Author Posted June 27, 2012 the code doesn't work. I assume you forgot #include <File.au3>, so I added it in, but it doesn't work too. can you check please? and of course you're right. more complicated is mor powerful.
DicatoroftheUSA Posted June 27, 2012 Posted June 27, 2012 (edited) It "doesn't work" is not very helpfull, if you want help you should expect to give at least a little. I probably left a space out somewhere. And don't expect any of us to wipe for you. Edited June 27, 2012 by DicatoroftheUSA Statism is violence, Taxation is theft. Autoit Wiki
svatvn Posted June 27, 2012 Author Posted June 27, 2012 It's line 4, error in expression. I tried to look for wrong spaces or quotes already
DicatoroftheUSA Posted June 27, 2012 Posted June 27, 2012 (edited) #include <File.au3> $sDir=@scriptdir $aFiles = _FileListToArray('"'&$sDir&'"', "*.reg") For $I = 1 To $aFiles[0] Run(@comspec & " /k Regedit.exe /S " & '"' & $sdir & "" & $aFiles[$I] & '"') consolewrite(@lf&"Regedit.exe /S " &'"'& $sdir & "" & $aFiles[$I] & '"'&@lf) Next I didn't forget the include, something is screwy with the paste script function of this forum at the moment. Edited June 27, 2012 by DicatoroftheUSA Statism is violence, Taxation is theft. Autoit Wiki
svatvn Posted June 27, 2012 Author Posted June 27, 2012 hey Dictator, thx again for checking, really thank you for helping me. but now it's line 7, "subscript used with non-Array variable" I still can't believe, that it is so complicated
BrewManNH Posted June 28, 2012 Posted June 28, 2012 Do you have any files in the script directory that end with the extension .reg? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now