One possible solution is PowerShell, which is very powerful on Windows. I wrote the following code:
1: # checks the number of inputs and only accepts one input
2: if( $args.Count -ne 1 )
3: {
4: # print usage information
5: Write-Host "Usage:" $MyInvocation.MyCommand.Name "path"
6: # exit
7: exit
8: }
9: # the first input is the path to the targeting directory
10: $directory = $args[0]
11: # find the number of sub-directories
12: $folders = Get-ChildItem $directory;
13: Write-Host $folders
14: # a fixed step size, which is 10
15: $step = 10
16: # checks all the sub-folders, such as 10 to 10+10, or 30 to 30+10
17: for($from=0; $from -lt $folders.Count; $from=$from+$step)
18: {
19: $to = $to+$step
20: # call my code and pass the parameters
21: ./WebSpider.exe $directory 2000 1 $from $to
22: }
When I want to run the script, there is an error popped up, which says the script file cannot be load because the execution of script is disabled. WTF… Are you guys at Microsoft kidding me?! You implemented a shell interface, but disabled it to users?! You need administrator authority to enable it by the following command, otherwise, you cannot run scripts with PowerShell.
Set-ExecutionPolicy RemoteSigned
UPDATE:
Powershell -ExecutionPolicy RemoteSigned
You could start power shell as above to enable script executions without administrator authority.
The students, like me, do not have administrator authority on the desktops in the lab. So I cannot use the scripted…
Finally, I decide to rewrite a batch version instead.
1: @echo off
2: IF "%1"=="" goto stop
3: set path=%1
4: echo %1%
5: set start=0
6: set step=10
7: rem count the number of folders
8: setlocal EnableDelayedExpansion
9: set /a count=0
10: for /d %%d in (%path%*) do (
11: set /a count+=1
12: rem @echo !count!. %%d
13: )
14: set /a end=%count%
15: ECHO Folder %end%
16: :loop
17: if %start% GTR %end% goto stop
18: set /a cur = %start%+%step%
19:
20: rem echo from %start% to %cur%
21: rem run the code
22: WebSpider.exe 2000 1 %start% %step% %1%
23:
24: set /a start = %cur%
25: goto loop
26: :stop
27: rem
I used to admit PowerShell very much, for its integration with DotNet and extendable command-let. However, I just cannot understand why Microsoft disables his own product by default?! You may argue that the users on Windows may make mistake and … It does not make any scene, either. If a shell interface cannot run script, can you find any other functionalities we need, from a shell?!