Jump to content

Replicate, change and Save As?


gavstead
 Share

Recommended Posts

Hi all,

I'm REALLY new to scripting and I think I've got a bit of a mountain to climb here. I seriously need help!

I have a website. This website needs to have different pages for every town in the UK. I have a template php page for this and inside this template page is a line of code ending with a bracketed number, like [0]. This bracketed number corresponds with a town name on a spreadsheet I have. The spreadsheet is simple. Column A has the town names. Column B has numbers, simply 1, 2, 3, etc. So, for example, Aberdeen = 1, Abergele = 2, and so on.

What I need to do is create a script which opens the template php page, finds the bracketed number, changes the number up one, then looks at the spreadsheet, finds the corresponding town name to that number and then saves the template with that town name as the filename and with a php extension.

So I will end up with a folder populated with a couple of thousand files, each with a unique filename of a town name and each with it's own unique bracketed number.

I need the option to browse to all variables (template file, spreadsheet, containing folder and destination folder) but only in the first instance. Not for every 'save as' action.

I'm not really sure of the best way forward. Would repeatedly using the template file for every 'save as' cause problems for replacing the number as there would be no trail of numbers to check against? Or would it be better to open the template to start and then use some kind of count function, building up each time from the last? As for the spreadsheet - changing that to a csv or text file is no problem if that helps.

But to be honest, I don't even know where to start!

Link to comment
Share on other sites

Hi.

I'm absolutely not sure, if I get your problem, but this should give you a start:

#include <file.au3>
#include <array.au3>
 
Dim $aInput
Dim $fileInput="Your-input-file.txt"
 
_FileReadToArray($fileInput, $aInput)
 
_ArrayDisplay($aInput)
 
For $i = 1 To $aInput[0]
    $aFoo = StringSplit($aInput[0], "=")
    _ArrayDisplay($aFoo,$i)
    $Name = $aFoo[1]
    $Number = $aFoo[2]
    ; maybe stringstripWS($name,1+2) required on top, same for $number
    $f = FileOpen($Name & "[" & $Number & "]", 2)
    FileWriteLine($f, "What you want to have in the file")
    FileClose($f)
Next
Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...