0

What are the equivalent commands in Windows if I have these commands in Linux?

if (!is_dir('geoip')) mkdir('geoip', 0744);
shell_exec('unzip -oj GeoLiteCity.zip -d geoip/');

shell_exec('rm -rf geoip/');
3
  • Still trying to determine which dialect of BASH this user's using. Never heard of is_dir or shell_exec in BASH. PHP... sure. But that's not BASH. (They're PHP commands)
    – lornix
    Jun 24, 2012 at 8:21
  • @lornix It is PHP. Arina, have you understood what these commands actually do? Do you know that they're shell commands wrapped in PHP? Have you tried looking for the Windows equivalents?
    – slhck
    Jun 24, 2012 at 8:34
  • @slhck, I'm sorry for my mistake. I just know from you and lornix that those scripts are PHP. I'm sorry, I'm newbie. That's why I ask. this is because I catch the rm and mkdir which I also know that they are command in Linux. But thanks for reminding that is PHP.
    – arina
    Jun 24, 2012 at 9:22

3 Answers 3

2

You should download and install GnuWin32 to get all the basic UNIX commands on Windows, for example, wget, sed, cat, grep, rm, mkdir, unzip – all you need.

http://sourceforge.net/projects/getgnuwin32/files/latest/download?source=files

2
  • with that application we can run the unix command in windows??
    – arina
    Jun 24, 2012 at 8:33
  • @arina Yes, you can.
    – slhck
    Jun 24, 2012 at 8:39
1

if you can afford to just ignore errors, then the following would work for your PHP commands:

(Hopefully you've got a statement prior to this putting your process in the proper subdirectory BEFORE you do this... like this)

cd c:\mystuff\temp\

mkdir geoip
unzip -oj GeoLiteCity.zip -d geoip/
rmdir /S /Q geoip/

If geoip already exists, the mkdir will return an error, but it's not fatal. Of course, if you unzip something on top of something pre-existing, you've got issues. But your original script doesn't cover that either.

rmdir /S /Q geoip/ will remove the subdir geoip and anything below it. same as rm -rf

BE CAREFUL with rmdir /S /Q, you can do stupid things with it quite easily.

4
  • deltree doesn't exist in XP, vista, or win7. "rmdir /S" is a good equivalent though.
    – RJFalconer
    Jun 24, 2012 at 9:16
  • I'll try your code @lornix. I'll tell you what happened after I've tried them. Thank You.
    – arina
    Jun 24, 2012 at 9:20
  • so what command in win7 to replace the "deltree"?
    – arina
    Jun 24, 2012 at 9:21
  • rmdir /S /Q geoip is equivalent to deltree /Y geoip, I've edited my answer
    – lornix
    Jun 24, 2012 at 9:24
0
  • Given a folder, unzips to that location
  • Given invalid path, makes dir and unzips
  • Given a file, renames that file to filename.old, makes dir and unzips

script.bat

@echo off

IF NOT EXIST %1 GOTO Make_Folder

REM File exists, test to see if it's a folder
REM Get attributes of first param. 
set ATTR=%~a1

REM if first character is "d", it's a folder
set DIRATTR=%ATTR:~0,1%
IF /I "%DIRATTR%"=="d" GOTO Extract

:Is_File
echo %1 already exists and will be renamed. 
pause
ren %1 %1.old

:Make_Folder
mkdir %1
attrib +r %1

:Extract
unzip -oj GeoLiteCity.zip -d geoip
echo Extraction test complete. Extracted files will now be deleted. 
pause
attrib -r -s -h %1
rmdir /S /Q %1

Usage

script "my folder"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .