February 02, 2021 Re: Article: Why I use the D programming language for scripting | ||||
---|---|---|---|---|
| ||||
Posted in reply to aberba | On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
> It's finally out!
>
> https://opensource.com/article/21/1/d-scripting
If the article is about scripting, then the article will contain examples of scripts used in business.
For example, to delete all dub caches in a directory:
Version via Windows .bat:
@echo off
FOR /D %%f IN ( .\* ) DO (
IF EXIST .\%%f\.dub (
echo .\%%f\.dub
rmdir /q /s .\%%f\.dub
)
)
Version via Dlang:
module dubcache;
import std.file;
import std.path;
import std.stdio;
void main( string[] args )
{
foreach( dir; dirEntries( args[0].dirName, SpanMode.shallow ) )
{
if ( dir.baseName == ".dub" )
{
writeln( "REMOVED: ", dir );
rmdirRecurse( dir.name );
}
}
}
or
module dubcache;
import std;
void main( string[] args )
{
dirEntries( args[0].dirName, SpanMode.shallow )
.filter!( a => a.baseName == ".dub" )
.each!(
( a )
{
writeln( a );
rmdirRecurse( a );
}
);
}
|
February 02, 2021 Re: Article: Why I use the D programming language for scripting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Виталий Фадеев | On Tuesday, 2 February 2021 at 03:53:43 UTC, Виталий Фадеев wrote: > On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote: >> It's finally out! >> >> https://opensource.com/article/21/1/d-scripting > > If the article is about scripting, then the article will contain examples of scripts used in business. > > For example, to delete all dub caches in a directory: Remove dub cache in subsirectories: module dubcache; // Reason: // each cache take 50 - 200 MB of disk space // Goal: // scan dirs and remove caches // // ./ // a/ // b/ // .dub/ <- target // c/ import std; void main( string[] args ) { dirEntries( args[0].dirName, SpanMode.shallow ) .filter!( a => a.isDir ) .map!( a => buildPath( a.name, ".dub" ) ) .filter!( a => a.exists ) .each!( ( a ) { writeln( a ); rmdirRecurse( a ); } ); } Source: https://run.dlang.io/is/ah1Vtp And we see what it not simple as windows .bat |
February 02, 2021 Re: Article: Why I use the D programming language for scripting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Виталий Фадеев | On Tuesday, 2 February 2021 at 04:24:48 UTC, Виталий Фадеев wrote:
> On Tuesday, 2 February 2021 at 03:53:43 UTC, Виталий Фадеев wrote:
>> On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
>>> It's finally out!
>>>
>>> https://opensource.com/article/21/1/d-scripting
>>
>> If the article is about scripting, then the article will contain examples of scripts used in business.
>>
> And we see what it not simple as windows .bat
Perhaps the best version would be a high-level add-on over rdmd with Dlang syntax.
.
"main()" and "import std" will be hidden.
For example, the final result will look like this:
dirEntries( args[0].dirName, SpanMode.shallow )
.filter!( a => a.isDir )
.map!( a => buildPath( a.name, ".dub" ) )
.filter!( a => a.exists )
.each!(
( a )
{
writeln( a );
rmdirRecurse( a );
}
);
and the file will have the extension ".ds"
|
February 02, 2021 Re: Article: Why I use the D programming language for scripting | ||||
---|---|---|---|---|
| ||||
Posted in reply to sighoya | On Monday, 1 February 2021 at 18:11:43 UTC, sighoya wrote:
> On Monday, 1 February 2021 at 13:37:38 UTC, Petar Kirov [ZombineDev] wrote:
>> Any dlang slack member can invite new members by their email (I think even temporary email addresses are fine). On which email shall I send you an invite?
>
> Is there any PM mechanism on board, no?
You mean does Slack have private messages? Yes it does.
|
February 02, 2021 Re: Article: Why I use the D programming language for scripting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Petar Kirov [ZombineDev] | On Tuesday, 2 February 2021 at 07:28:36 UTC, Petar Kirov [ZombineDev] wrote:
> On Monday, 1 February 2021 at 18:11:43 UTC, sighoya wrote:
>> Is there any PM mechanism on board, no?
>
> You mean does Slack have private messages? Yes it does.
No I meant, if this board has such options, don't like to paste email data in their.
Anyway, could you invite me over the following mail:
<my forum username>@gmail.com
That would be nice.
I'm interested in chat discussions.
|
February 02, 2021 Re: Article: Why I use the D programming language for scripting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Виталий Фадеев | On Tuesday, 2 February 2021 at 03:53:43 UTC, Виталий Фадеев wrote:
> On Sunday, 31 January 2021 at 20:36:43 UTC, aberba wrote:
>> [...]
>
> If the article is about scripting, then the article will contain examples of scripts used in business.
>
> [...]
Nice examples!
|
Copyright © 1999-2021 by the D Language Foundation