Sign in to follow this  
Followers 0
codeseeker

Need help creating an array.

3 posts in this topic

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.

Share this post


Link to post
Share on other sites



What code do you have so far ?


Share this post


Link to post
Share on other sites

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

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

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