Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help to write a script. 1

Status
Not open for further replies.

ak77bd

Programmer
May 9, 2008
4
US
Hi
I am very new at writing script. I found some what a close suggestion in this thread called: thread329-957274, but its not clear enough for me.

Problem: I need to automate this process:

File will be created as csv by a 3rp pary software.
I need to check for that file in a specific time. if any .csv file exsits
1. i need to copy it to a folder (thats easy)
2. open it up and sort it by it column E (Asc), F(Asc) and C (decending).
3. Save it as a .dat file. (which will creat another copy...)

Please help
 
Your problem is going to be sorting the file. Most languages don't have tools to sort csv files especially by ASC and DESC at the same time. I did a quick google and I did see some PHP and Perl scripts, you might find one that fits your needs.

The easiest thing would be to bring it into Excel or Access, sort it then save it. But then it is harder to script the total soulution without human intervention.

Simi
 
You can easily script bringing the CSV file into Excel. Then you can automate the sort via vbscript as well.

Take a look at thread329-1433373 for importing into Excel.

And an example for sorting:

Code:
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add
Set objWorksheet = objWorkbook.Worksheets(1)

objExcel.Cells(1, 1).Value = "4"
objExcel.Cells(2, 1).Value = "1"
objExcel.Cells(3, 1).Value = "2"
objExcel.Cells(4, 1).Value = "3"
objExcel.Cells(1, 2).Value = "A"
objExcel.Cells(2, 2).Value = "B"
objExcel.Cells(3, 2).Value = "C"
objExcel.Cells(4, 2).Value = "D"

Set objRange = objWorksheet.UsedRange
Set objRange2 = objExcel.Range("A1")
objRange.Sort(objRange2)

Take a look here for an explanation of Excel sorting:
I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top