Tigerweld Posted October 7, 2010 Posted October 7, 2010 how can I loop thru a directory and run any batch files that may be present? Can you use a wild card for the filename and use the .bat extension?
PsaltyDS Posted October 7, 2010 Posted October 7, 2010 _FileListToArray() See help file. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Ascend4nt Posted October 7, 2010 Posted October 7, 2010 (edited) How about good ol' DOS style commands. Send this to @comspec and it will only cost you one line of code: for %f in (*.bat) do "%f" *edit: you don't need 'start', plus start seems to screw up with double-quotes Edited October 7, 2010 by Ascend4nt My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
Tigerweld Posted October 14, 2010 Author Posted October 14, 2010 _FileListToArray() See help file. OK I am using the FileListToArray, but when I try and run it I'm not getting the actually file name. I do if I uncomment the _ArrayDisplay, but on the line with the msgbox it is showing the filename as *.bat. HELP! #Include <File.au3> #Include <Array.au3> $sPath = "\\serverName\wol$\" $sFilter = "*.bat" $FileList=_FileListToArray($sPath, $sFilter) ;_ArrayDisplay($FileList,"$FileList") For $i = 1 To UBound ($FileList) - 1 run($sPath & $sFilter) MsgBox(4096, "Workstation", $sPath & $sFilter) Next
PsaltyDS Posted October 14, 2010 Posted October 14, 2010 $FileList is an array. You need to learn how to reference the contents of an array. See "Variables" in the help file, and there is a good wiki on it. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
BrewManNH Posted October 14, 2010 Posted October 14, 2010 OK I am using the FileListToArray, but when I try and run it I'm not getting the actually file name. I do if I uncomment the _ArrayDisplay, but on the line with the msgbox it is showing the filename as *.bat. HELP! #Include <File.au3> #Include <Array.au3> $sPath = "\\serverName\wol$\" $sFilter = "*.bat" $FileList=_FileListToArray($sPath, $sFilter) ;_ArrayDisplay($FileList,"$FileList") For $i = 1 To UBound ($FileList) - 1 run($sPath & $sFilter) MsgBox(4096, "Workstation", $sPath & $sFilter) Next You created the array $FileList, but then in your For..Next loop you referenced the original $sPath and $sFilter, so of course that's what the MsgBox is going to display. You need to change the MsgBox code to this: MsgBox(4096, "Workstation", $FileList[$i]) This will show you what's contained in each element of the $FileList array, one element at a time. 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
Ascend4nt Posted October 14, 2010 Posted October 14, 2010 Again, the simplest solution: $sFolderToUse="C:\batchfiles" Run(@ComSpec&' /c for %f in (*.bat) do "%f"',$sFolderToUse) My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
Tigerweld Posted October 14, 2010 Author Posted October 14, 2010 Again, the simplest solution: $sFolderToUse="C:\batchfiles" Run(@ComSpec&' /c for %f in (*.bat) do "%f"',$sFolderToUse) Hey I'm all about simple solutions, however when I use this I get an error about an internal command not recognized because the batch file has command lines in it. I can run them individually and it works fine. Thanks for helping!
Tigerweld Posted October 14, 2010 Author Posted October 14, 2010 $FileList is an array. You need to learn how to reference the contents of an array. See "Variables" in the help file, and there is a good wiki on it. Am I closer? lol This is killing me! #Include <File.au3> #Include <Array.au3> $sPath = "\\serverName\wol$\" $sFilter = "*.bat" $FileList=_FileListToArray($sPath, $sFilter) ;_ArrayDisplay($FileList,"$FileList") For $i = 1 To $FileList[0] Run($FileList[$i]) Sleep(100) ;MsgBox(0, $i, $FileList[$i]) Next
Ascend4nt Posted October 14, 2010 Posted October 14, 2010 Hey I'm all about simple solutions, however when I use this I get an error about an internal command not recognized because the batch file has command lines in it. I can run them individually and it works fine. Thanks for helping!I'm curious what internal command isn't recognized? I've tried it with multiple batch files with varying internal and external commands without any problems. Could you change the /c to a /k and see what it is reporting in the command prompt? My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
Tigerweld Posted October 14, 2010 Author Posted October 14, 2010 Am I closer? lol This is killing me! #Include <File.au3> #Include <Array.au3> $sPath = "\\serverName\wol$\" $sFilter = "*.bat" $FileList=_FileListToArray($sPath, $sFilter) ;_ArrayDisplay($FileList,"$FileList") For $i = 1 To $FileList[0] Run($FileList[$i]) Sleep(100) ;MsgBox(0, $i, $FileList[$i]) Next No better using the /k. An example of one of the batch files is wolcmd 00:0F:FE:35:86:FC 10.152.1.36 255.255.255.0 8900 It's not recognizing the wolcmd, but it works if I manually run the batch file so I know there isn't anything wrong with the command.
ZacUSNYR Posted October 14, 2010 Posted October 14, 2010 (edited) #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: ZacUSNYR Script Function: Get Batch Files from a Directory #ce ---------------------------------------------------------------------------- #Include <File.au3> Global $sourceDirFileList Global $sourceDir = "C:\temp" Dim $MsgBoxAnswer $sourceDirFileList = _FileListToArray($sourceDir, "*.bat", 1) For $i = 1 To $sourceDirFileList[0] $MsgBoxAnswer = MsgBox(36, "Run Batch File?", "Do you wish to run batch file : " & $sourcedir & Chr(92) & $sourceDirFileList[$i]) Select Case $MsgBoxAnswer = 6 Run(@ComSpec & ' /c "' & $sourcedir & Chr(92) & $sourceDirFileList[$i] & '"') Case $MsgBoxAnswer = 7 MsgBox(0, "Skipped", "Skipped batch file : " & $sourceDirFileList[$i]) EndSelect Next That's how i'd go about it. Need to remember the Array is saving the file name but it's not saving the path. So if you're not running your script in that path it will not work. Edited October 14, 2010 by ZacUSNYR
Ascend4nt Posted October 14, 2010 Posted October 14, 2010 No better using the /k. An example of one of the batch files is wolcmd 00:0F:FE:35:86:FC 10.152.1.36 255.255.255.0 8900 It's not recognizing the wolcmd, but it works if I manually run the batch file so I know there isn't anything wrong with the command. wolcmd.exe is not a built-in command, and its location either needs to be in the "Path" environment variable, or the file needs to be where the batch files are at, or the batch files themselves could be edited to have full paths to that program. The reason it probably works when you run the batch file manually depends on where you are running the batch file from and where wolcmd.exe exists. You can also keep the current folder and run the command prompt from there using a slight tweak: Run(@ComSpec&' /c for %f in ("'&$sFolderToUse&'\*.bat") do "%f"') My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
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