Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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/');
share|improve this question
    
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 '12 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 '12 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 '12 at 9:22
add comment

3 Answers

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

share|improve this answer
    
with that application we can run the unix command in windows?? –  arina Jun 24 '12 at 8:33
    
@arina Yes, you can. –  slhck Jun 24 '12 at 8:39
add comment

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.

share|improve this answer
    
deltree doesn't exist in XP, vista, or win7. "rmdir /S" is a good equivalent though. –  RJFalconer Jun 24 '12 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 '12 at 9:20
    
so what command in win7 to replace the "deltree"? –  arina Jun 24 '12 at 9:21
    
rmdir /S /Q geoip is equivalent to deltree /Y geoip, I've edited my answer –  lornix Jun 24 '12 at 9:24
add comment
  • 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"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.