Jump to content

Recommended Posts

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

Link to post
Share on other sites

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 Gude
How 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

Link to post
Share on other sites

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".

Link to post
Share on other sites

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to post
Share on other sites
  • Moderators

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 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!

Link to post
Share on other sites

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

Link to post
Share on other sites

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 by svatvn
Link to post
Share on other sites

sorry, I don' get it :D

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? :huh:

Edited by svatvn
Link to post
Share on other sites

#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? Posted Image

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 by DicatoroftheUSA
Link to post
Share on other sites

#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 by DicatoroftheUSA
Link to post
Share on other sites

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 Gude
How 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

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...