codeseeker Posted November 20, 2013 Share Posted November 20, 2013 I have been tasked with renaming the same filename located in the same path on several hosts. I have already created the script that will rename using Filemove. I now need to understand how I can I create an array, that can store each line of a text file or excel column that displays the hostname as a variable and run the script to rename it . Sorry for such a basic request but I am fairly new to this. I have attempted to look at some of the examples for Arrays but just couldn't grasp what I need to do in this exact scenario. Link to comment Share on other sites More sharing options...
Nirvana6 Posted November 20, 2013 Share Posted November 20, 2013 What code do you have so far ? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted November 21, 2013 Moderators Share Posted November 21, 2013 Hi, ImperialLeader. No apologies necessary for being new; we've all had a Day 1. But it will greatly help us help you if you are more specific on your needs; the process for getting an array from a text file vs. an excel file are different. I have posted short examples of each below, please use the help file to familiarize yourself with the different functions. You'll then be better equipped to decide which method is best for you, and expand on it if needed. If you have any questions, please ask. In a text file or Column A in an Excel spreadsheet: WinXP1 WinXP2 WinXP3 WinXP4 WinXP5 Win7Laptop1 Win7Laptop2 Win7Laptop3 Win7Laptop4 Win7Laptop5 ;Simple example for a text file #include <Array.au3> #include <File.au3> Local $aText ;create your array variable _FileReadToArray(@DesktopDir & "\Test.txt", $aText) ;read your text file into the array _ArrayDisplay($aText) ;to verify your data is in the array For $i = 1 To $aText[0] ;loop through all of the elements in your array to perform whatever action you would like. ;do stuff Next ;Simple example for an Excel spreadsheet #include <Array.au3> #include <Excel.au3> $oExcel = _ExcelBookOpen(@DesktopDir & "\Test.xls") ;Declare a variable for the workbook and open it. $aCells = _ExcelReadArray($oExcel, 1, 1, 10, 1) ;Read column 1, beginning at row 1, for 10 cells, reading downward, into an array _ArrayDisplay($aCells) ;Verify your data is in the array For $element In $aCells ;Loop through the elements in your array to perform whatever action you would like. ;do stuff Next "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 comment Share on other sites More sharing options...
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