JasonDavis
JasonDavis

Reputation: 48973

PHP command-line tool to work on Windows

All the code/commands below are part of a PHP script that processes images from the command line, it is for a Linux system, I need to figure out how to translate these commands to work on a Windows system.

I thought about possibly switching it to use the native PHP filesystem functions but I am not sure because of things like -rf and -f that are in these commands below.

Could someone please help me, I need the 5 below translated to work in a PHP script on a Windows system instead of Unix/linux

line 100
exec("rm -rf {$this->tmp_path}");

line 219
exec("rm -f $raw_file");

line 281
exec("mv $quant_file {$this->tmp_path}/{$src_filename}-quant.png");

line 289
exec("rm -f $quant_file");

line 295
exec("rm -f $out_file");

Upvotes: 0

Views: 205

Answers (1)

Joey
Joey

Reputation: 354824

  • rm -rfrd /s /q
  • rm -fdel /f
  • mvmove

Of course, if you want your script to work on both Windows and Unix, then you have some more work to do. But the PHP native functions (rmdir, unlink and rename) are trivial to use in this case, actually:

rmdir($this->tmp_path);
unlink($raw_file);
rename($quant_file, "{$this->tmp_path}/{$src_filename}-quant.png");
unlink($quant_file);
unlink($out_file);

(Roughly, it's untested and I haven't touched PHP in half a decade.)

Upvotes: 4

Related Questions