0

I am making script to convert excel files into csv files. Excel files are in downloads folder and start with "START". Only the first file is converted and then php is still running, but nothing happens. Running it from browser I can see the circle is running eternally, like loading the website. This is the code:

$path = "C:\Users\\tom\Downloads\\";


foreach(glob($path."*.xls") as $excel_file) {
    $substr = substr($excel_file, 24, 5);
    if($substr = "START") {
        $csv_file = str_replace(".xls", ".csv", $excel_file);
        exec("$path"."csv.vbs $excel_file $csv_file");
    }
}

the script I am using is csv.vbs script and the code is:

if WScript.Arguments.Count < 2 Then
    WScript.Echo "Error! Please specify the source path and the destination. Usage: XlsToCsv SourcePath.xls Destination.csv"
    Wscript.Quit
End If
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))
oBook.SaveAs WScript.Arguments.Item(1), 6
oBook.Close False
oExcel.Quit
WScript.Echo "Done" 

using shell_exec is the same. What is wrong here?

2
  • Any spaces in your file names? Commented Aug 29, 2015 at 0:07
  • @TimWilliams no spaces Commented Aug 29, 2015 at 0:18

2 Answers 2

1

$substr is not equal to "START" according to php.net

substr ( string $string , int $start [, int $length ] )

and START is the 5 characters so

$substr = substr($excel_file, 0, 5);

and there is a wrong comparison try

if($substr = "START") 

the right comparison is by using == or === for strict comparison

if($substr == "START")
Sign up to request clarification or add additional context in comments.

1 Comment

you are right about the comparison, but it wasn't the reason. Ill give you upvote
0

Removed the last line in csv.vbs

WScript.Echo "Done" 

and it's working fine

1 Comment

if the wscript.echo was your issue then your computer is set to use WScript as the default script host (which is the default) and is popping a message box (even though you might not be able to see it, check your task manager for unused wscript processes). If you want to continue to use wscript.echo in your scripts, either use cscript csv.vbs when calling your script (and every script subsequently). Or run cscript //H:CScript at a command prompt to change the default script host on your computer to cscript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.