Sign in to follow this  
Followers 0
svatvn

for loop, like batch

25 posts in this topic

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

Share this post


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

Share this post


Link to post
Share on other sites

hi BrewMan,

it doesnt work :D

and I also tried to replace C:pathname with @ScriptDir, but it doesnt work either...

can you check to code please?

Share this post


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

Share this post


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!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

thx everybody,

but the reg-files are in the scriptfolder, how would the code be for that?

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by svatvn

Share this post


Link to post
Share on other sites

#9 ·  Posted (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 by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


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

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by svatvn

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#14 ·  Posted (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? 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

Share this post


Link to post
Share on other sites

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. :D

Share this post


Link to post
Share on other sites

#16 ·  Posted (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 by DicatoroftheUSA

Share this post


Link to post
Share on other sites

It's line 4, error in expression. I tried to look for wrong spaces or quotes already :D

Share this post


Link to post
Share on other sites

#18 ·  Posted (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 by DicatoroftheUSA

Share this post


Link to post
Share on other sites

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 :D

Share this post


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

Share this post


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
Sign in to follow this  
Followers 0