WeixiangYan/CodeTransOcean huggingface dataset:
Task: Gapful numbers



C#: using System;

namespace GapfulNumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("The first 30 gapful numbers are: ");
            
            FindGap(100, 30);

            Console.WriteLine("The first 15 gapful numbers > 1,000,000 are: ");
            FindGap(1000000, 15);

            Console.WriteLine("The first 10 gapful numbers > 1,000,000,000 are: ");
            FindGap(1000000000, 10);

            Console.Read();
        }

        public static int firstNum(int n)
        {
            
            while (n >= 10)
            {
                n /= 10;
            }
            return (n);
        }

        public static int lastNum(int n)
        {
            
            return (n % 10);
        }

        static void FindGap(int n, int gaps)
        {
            int count = 0;
            while (count < gaps)
            {

                
                string concat = firstNum(n).ToString() + lastNum(n).ToString();
                
                int i = Convert.ToInt32(concat);

                
                if (n % i == 0)
                {
                    Console.Write(n + " ");
                    count++;
                    n++;
                }
                else
                {
                    n++;
                    continue;
                }
            }
        }
    }
}







COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. GAPFUL.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 COMPUTATION.
            02 N            PIC 9(10).
            02 N-DIGITS     REDEFINES N.
               03 ND        PIC 9 OCCURS 10 TIMES.
            02 DIV-CHECK    PIC 9(10)V9(2).
            02 DIV-PARTS    REDEFINES DIV-CHECK.
               03 DIV-INT   PIC 9(10).
               03 DIV-FRAC  PIC 9(2).
            02 GAP-AMOUNT   PIC 99.
            02 GAP-DSOR     PIC 99.
            02 FIRST-DIGIT  PIC 99.
        01 OUTPUT-FORMAT.
            02 N-OUT        PIC Z(10).
            
        PROCEDURE DIVISION.
        BEGIN.
            DISPLAY "First 30 gapful numbers >= 100:".
            MOVE 100 TO N. MOVE 30 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 15 gapful numbers >= 1000000:".
            MOVE 1000000 TO N. MOVE 15 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 10 gapful numbers >= 1000000000:".
            MOVE 1000000000 TO N. MOVE 10 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            STOP RUN.
        
        CHECK-GAPFUL-NUMBER.
            SET FIRST-DIGIT TO 1.
            INSPECT N TALLYING FIRST-DIGIT FOR LEADING '0'.
            COMPUTE GAP-DSOR = ND(FIRST-DIGIT) * 10 + ND(10).
            DIVIDE N BY GAP-DSOR GIVING DIV-CHECK.
            IF DIV-FRAC IS EQUAL TO 0
                MOVE N TO N-OUT
                DISPLAY N-OUT
                SUBTRACT 1 FROM GAP-AMOUNT.
            ADD 1 TO N.
            IF GAP-AMOUNT IS GREATER THAN 0 
                GO TO CHECK-GAPFUL-NUMBER.
Task: Gapful numbers


C++: #include <iostream>

bool gapful(int n) {
    int m = n;
    while (m >= 10)
        m /= 10;
    return n % ((n % 10) + 10 * (m % 10)) == 0;
}

void show_gapful_numbers(int n, int count) {
    std::cout << "First " << count << " gapful numbers >= " << n << ":\n";
    for (int i = 0; i < count; ++n) {
        if (gapful(n)) {
            if (i != 0)
                std::cout << ", ";
            std::cout << n;
            ++i;
        }
    }
    std::cout << '\n';
}

int main() {
    show_gapful_numbers(100, 30);
    show_gapful_numbers(1000000, 15);
    show_gapful_numbers(1000000000, 10);
    return 0;
}








COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. GAPFUL.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 COMPUTATION.
            02 N            PIC 9(10).
            02 N-DIGITS     REDEFINES N.
               03 ND        PIC 9 OCCURS 10 TIMES.
            02 DIV-CHECK    PIC 9(10)V9(2).
            02 DIV-PARTS    REDEFINES DIV-CHECK.
               03 DIV-INT   PIC 9(10).
               03 DIV-FRAC  PIC 9(2).
            02 GAP-AMOUNT   PIC 99.
            02 GAP-DSOR     PIC 99.
            02 FIRST-DIGIT  PIC 99.
        01 OUTPUT-FORMAT.
            02 N-OUT        PIC Z(10).
            
        PROCEDURE DIVISION.
        BEGIN.
            DISPLAY "First 30 gapful numbers >= 100:".
            MOVE 100 TO N. MOVE 30 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 15 gapful numbers >= 1000000:".
            MOVE 1000000 TO N. MOVE 15 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 10 gapful numbers >= 1000000000:".
            MOVE 1000000000 TO N. MOVE 10 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            STOP RUN.
        
        CHECK-GAPFUL-NUMBER.
            SET FIRST-DIGIT TO 1.
            INSPECT N TALLYING FIRST-DIGIT FOR LEADING '0'.
            COMPUTE GAP-DSOR = ND(FIRST-DIGIT) * 10 + ND(10).
            DIVIDE N BY GAP-DSOR GIVING DIV-CHECK.
            IF DIV-FRAC IS EQUAL TO 0
                MOVE N TO N-OUT
                DISPLAY N-OUT
                SUBTRACT 1 FROM GAP-AMOUNT.
            ADD 1 TO N.
            IF GAP-AMOUNT IS GREATER THAN 0 
                GO TO CHECK-GAPFUL-NUMBER.
Task: Gapful numbers





Java: import java.util.List;

public class GapfulNumbers {
    private static String commatize(long n) {
        StringBuilder sb = new StringBuilder(Long.toString(n));
        int le = sb.length();
        for (int i = le - 3; i >= 1; i -= 3) {
            sb.insert(i, ',');
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        List<Long> starts = List.of((long) 1e2, (long) 1e6, (long) 1e7, (long) 1e9, (long) 7123);
        List<Integer> counts = List.of(30, 15, 15, 10, 25);
        for (int i = 0; i < starts.size(); ++i) {
            int count = 0;
            Long j = starts.get(i);
            long pow = 100;
            while (j >= pow * 10) {
                pow *= 10;
            }
            System.out.printf("First %d gapful numbers starting at %s:\n", counts.get(i), commatize(starts.get(i)));
            while (count < counts.get(i)) {
                long fl = (j / pow) * 10 + (j % 10);
                if (j % fl == 0) {
                    System.out.printf("%d ", j);
                    count++;
                }
                j++;
                if (j >= 10 * pow) {
                    pow *= 10;
                }
            }
            System.out.println('\n');
        }
    }
}





COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. GAPFUL.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 COMPUTATION.
            02 N            PIC 9(10).
            02 N-DIGITS     REDEFINES N.
               03 ND        PIC 9 OCCURS 10 TIMES.
            02 DIV-CHECK    PIC 9(10)V9(2).
            02 DIV-PARTS    REDEFINES DIV-CHECK.
               03 DIV-INT   PIC 9(10).
               03 DIV-FRAC  PIC 9(2).
            02 GAP-AMOUNT   PIC 99.
            02 GAP-DSOR     PIC 99.
            02 FIRST-DIGIT  PIC 99.
        01 OUTPUT-FORMAT.
            02 N-OUT        PIC Z(10).
            
        PROCEDURE DIVISION.
        BEGIN.
            DISPLAY "First 30 gapful numbers >= 100:".
            MOVE 100 TO N. MOVE 30 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 15 gapful numbers >= 1000000:".
            MOVE 1000000 TO N. MOVE 15 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 10 gapful numbers >= 1000000000:".
            MOVE 1000000000 TO N. MOVE 10 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            STOP RUN.
        
        CHECK-GAPFUL-NUMBER.
            SET FIRST-DIGIT TO 1.
            INSPECT N TALLYING FIRST-DIGIT FOR LEADING '0'.
            COMPUTE GAP-DSOR = ND(FIRST-DIGIT) * 10 + ND(10).
            DIVIDE N BY GAP-DSOR GIVING DIV-CHECK.
            IF DIV-FRAC IS EQUAL TO 0
                MOVE N TO N-OUT
                DISPLAY N-OUT
                SUBTRACT 1 FROM GAP-AMOUNT.
            ADD 1 TO N.
            IF GAP-AMOUNT IS GREATER THAN 0 
                GO TO CHECK-GAPFUL-NUMBER.
Task: Gapful numbers







Python: from itertools import islice, count
for start, n in [(100, 30), (1_000_000, 15), (1_000_000_000, 10)]:
    print(f"\nFirst {n} gapful numbers from {start:_}")
    print(list(islice(( x for x in count(start) 
                        if (x % (int(str(x)[0]) * 10 + (x % 10)) == 0) )
                      , n)))



COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. GAPFUL.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 COMPUTATION.
            02 N            PIC 9(10).
            02 N-DIGITS     REDEFINES N.
               03 ND        PIC 9 OCCURS 10 TIMES.
            02 DIV-CHECK    PIC 9(10)V9(2).
            02 DIV-PARTS    REDEFINES DIV-CHECK.
               03 DIV-INT   PIC 9(10).
               03 DIV-FRAC  PIC 9(2).
            02 GAP-AMOUNT   PIC 99.
            02 GAP-DSOR     PIC 99.
            02 FIRST-DIGIT  PIC 99.
        01 OUTPUT-FORMAT.
            02 N-OUT        PIC Z(10).
            
        PROCEDURE DIVISION.
        BEGIN.
            DISPLAY "First 30 gapful numbers >= 100:".
            MOVE 100 TO N. MOVE 30 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 15 gapful numbers >= 1000000:".
            MOVE 1000000 TO N. MOVE 15 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 10 gapful numbers >= 1000000000:".
            MOVE 1000000000 TO N. MOVE 10 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            STOP RUN.
        
        CHECK-GAPFUL-NUMBER.
            SET FIRST-DIGIT TO 1.
            INSPECT N TALLYING FIRST-DIGIT FOR LEADING '0'.
            COMPUTE GAP-DSOR = ND(FIRST-DIGIT) * 10 + ND(10).
            DIVIDE N BY GAP-DSOR GIVING DIV-CHECK.
            IF DIV-FRAC IS EQUAL TO 0
                MOVE N TO N-OUT
                DISPLAY N-OUT
                SUBTRACT 1 FROM GAP-AMOUNT.
            ADD 1 TO N.
            IF GAP-AMOUNT IS GREATER THAN 0 
                GO TO CHECK-GAPFUL-NUMBER.
Task: Gapful numbers








VB: Module Module1

    Function FirstNum(n As Integer) As Integer
        REM Divide by ten until the leading digit remains.
        While n >= 10
            n /= 10
        End While
        Return n
    End Function

    Function LastNum(n As Integer) As Integer
        REM Modulo gives you the last digit.
        Return n Mod 10
    End Function

    Sub FindGap(n As Integer, gaps As Integer)
        Dim count = 0
        While count < gaps
            Dim i = FirstNum(n) * 10 + LastNum(n)

            REM Modulo with our new integer and output the result.
            If n Mod i = 0 Then
                Console.Write("{0} ", n)
                count += 1
            End If

            n += 1
        End While
        Console.WriteLine()
        Console.WriteLine()
    End Sub

    Sub Main()
        Console.WriteLine("The first 30 gapful numbers are: ")
        FindGap(100, 30)

        Console.WriteLine("The first 15 gapful numbers > 1,000,000 are: ")
        FindGap(1000000, 15)

        Console.WriteLine("The first 10 gapful numbers > 1,000,000,000 are: ")
        FindGap(1000000000, 10)
    End Sub

End Module


COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. GAPFUL.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 COMPUTATION.
            02 N            PIC 9(10).
            02 N-DIGITS     REDEFINES N.
               03 ND        PIC 9 OCCURS 10 TIMES.
            02 DIV-CHECK    PIC 9(10)V9(2).
            02 DIV-PARTS    REDEFINES DIV-CHECK.
               03 DIV-INT   PIC 9(10).
               03 DIV-FRAC  PIC 9(2).
            02 GAP-AMOUNT   PIC 99.
            02 GAP-DSOR     PIC 99.
            02 FIRST-DIGIT  PIC 99.
        01 OUTPUT-FORMAT.
            02 N-OUT        PIC Z(10).
            
        PROCEDURE DIVISION.
        BEGIN.
            DISPLAY "First 30 gapful numbers >= 100:".
            MOVE 100 TO N. MOVE 30 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 15 gapful numbers >= 1000000:".
            MOVE 1000000 TO N. MOVE 15 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 10 gapful numbers >= 1000000000:".
            MOVE 1000000000 TO N. MOVE 10 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            STOP RUN.
        
        CHECK-GAPFUL-NUMBER.
            SET FIRST-DIGIT TO 1.
            INSPECT N TALLYING FIRST-DIGIT FOR LEADING '0'.
            COMPUTE GAP-DSOR = ND(FIRST-DIGIT) * 10 + ND(10).
            DIVIDE N BY GAP-DSOR GIVING DIV-CHECK.
            IF DIV-FRAC IS EQUAL TO 0
                MOVE N TO N-OUT
                DISPLAY N-OUT
                SUBTRACT 1 FROM GAP-AMOUNT.
            ADD 1 TO N.
            IF GAP-AMOUNT IS GREATER THAN 0 
                GO TO CHECK-GAPFUL-NUMBER.
Task: Gapful numbers




Go: package main

import "fmt"

func commatize(n uint64) string {
    s := fmt.Sprintf("%d", n)
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    return s
}

func main() {
    starts := []uint64{1e2, 1e6, 1e7, 1e9, 7123}
    counts := []int{30, 15, 15, 10, 25}
    for i := 0; i < len(starts); i++ {
        count := 0
        j := starts[i]
        pow := uint64(100)
        for {
            if j < pow*10 {
                break
            }
            pow *= 10
        }
        fmt.Printf("First %d gapful numbers starting at %s:\n", counts[i], commatize(starts[i]))
        for count < counts[i] {
            fl := (j/pow)*10 + (j % 10)
            if j%fl == 0 {
                fmt.Printf("%d ", j)
                count++
            }
            j++
            if j >= 10*pow {
                pow *= 10
            }
        }
        fmt.Println("\n")
    }
}






COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. GAPFUL.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 COMPUTATION.
            02 N            PIC 9(10).
            02 N-DIGITS     REDEFINES N.
               03 ND        PIC 9 OCCURS 10 TIMES.
            02 DIV-CHECK    PIC 9(10)V9(2).
            02 DIV-PARTS    REDEFINES DIV-CHECK.
               03 DIV-INT   PIC 9(10).
               03 DIV-FRAC  PIC 9(2).
            02 GAP-AMOUNT   PIC 99.
            02 GAP-DSOR     PIC 99.
            02 FIRST-DIGIT  PIC 99.
        01 OUTPUT-FORMAT.
            02 N-OUT        PIC Z(10).
            
        PROCEDURE DIVISION.
        BEGIN.
            DISPLAY "First 30 gapful numbers >= 100:".
            MOVE 100 TO N. MOVE 30 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 15 gapful numbers >= 1000000:".
            MOVE 1000000 TO N. MOVE 15 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            
            DISPLAY " ".
            DISPLAY "First 10 gapful numbers >= 1000000000:".
            MOVE 1000000000 TO N. MOVE 10 TO GAP-AMOUNT.
            PERFORM CHECK-GAPFUL-NUMBER.
            STOP RUN.
        
        CHECK-GAPFUL-NUMBER.
            SET FIRST-DIGIT TO 1.
            INSPECT N TALLYING FIRST-DIGIT FOR LEADING '0'.
            COMPUTE GAP-DSOR = ND(FIRST-DIGIT) * 10 + ND(10).
            DIVIDE N BY GAP-DSOR GIVING DIV-CHECK.
            IF DIV-FRAC IS EQUAL TO 0
                MOVE N TO N-OUT
                DISPLAY N-OUT
                SUBTRACT 1 FROM GAP-AMOUNT.
            ADD 1 TO N.
            IF GAP-AMOUNT IS GREATER THAN 0 
                GO TO CHECK-GAPFUL-NUMBER.
Task: Make directory path



C#: System.IO.Directory.CreateDirectory(path)









Ada: with Ada.Command_Line;
with Ada.Directories;
with Ada.Text_IO;

procedure Make_Directory_Path is
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put_Line ("Usage: make_directory_path <path/to/dir>");
      return;
   end if;

   declare
      Path : String renames Ada.Command_Line.Argument (1);
   begin
      Ada.Directories.Create_Path (Path);
   end;
end Make_Directory_Path;
Task: Make directory path

C: #include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>

int main (int argc, char **argv) {
    char *str, *s;
    struct stat statBuf;

    if (argc != 2) {
        fprintf (stderr, "usage: %s <path>\n", basename (argv[0]));
        exit (1);
    }
    s = argv[1];
    while ((str = strtok (s, "/")) != NULL) {
        if (str != s) {
            str[-1] = '/';
        }
        if (stat (argv[1], &statBuf) == -1) {
            mkdir (argv[1], 0);
        } else {
            if (! S_ISDIR (statBuf.st_mode)) {
                fprintf (stderr, "couldn't create directory %s\n", argv[1]);
                exit (1);
            }
        }
        s = NULL;
    }
    return 0;
}











Ada: with Ada.Command_Line;
with Ada.Directories;
with Ada.Text_IO;

procedure Make_Directory_Path is
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put_Line ("Usage: make_directory_path <path/to/dir>");
      return;
   end if;

   declare
      Path : String renames Ada.Command_Line.Argument (1);
   begin
      Ada.Directories.Create_Path (Path);
   end;
end Make_Directory_Path;
Task: Make directory path


C++: #include <filesystem>
#include <iostream>

namespace fs = std::filesystem;

int main(int argc, char* argv[])
{
	if(argc != 2)
	{
		std::cout << "usage: mkdir <path>\n";
		return -1;
	}

	fs::path pathToCreate(argv[1]);

	if (fs::exists(pathToCreate))
		return 0;

	if (fs::create_directories(pathToCreate))
		return 0;
	else
	{
		std::cout << "couldn't create directory: " << pathToCreate.string() << std::endl;
		return -1;
	}
}










Ada: with Ada.Command_Line;
with Ada.Directories;
with Ada.Text_IO;

procedure Make_Directory_Path is
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put_Line ("Usage: make_directory_path <path/to/dir>");
      return;
   end if;

   declare
      Path : String renames Ada.Command_Line.Argument (1);
   begin
      Ada.Directories.Create_Path (Path);
   end;
end Make_Directory_Path;
Task: Make directory path




Go: 	os.MkdirAll("/tmp/some/path/to/dir", 0770)








Ada: with Ada.Command_Line;
with Ada.Directories;
with Ada.Text_IO;

procedure Make_Directory_Path is
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put_Line ("Usage: make_directory_path <path/to/dir>");
      return;
   end if;

   declare
      Path : String renames Ada.Command_Line.Argument (1);
   begin
      Ada.Directories.Create_Path (Path);
   end;
end Make_Directory_Path;
Task: Make directory path





Java: import java.io.File;

public interface Test {

    public static void main(String[] args) {
        try {
            File f = new File("C:/parent/test");
            if (f.mkdirs())
                System.out.println("path successfully created");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}







Ada: with Ada.Command_Line;
with Ada.Directories;
with Ada.Text_IO;

procedure Make_Directory_Path is
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put_Line ("Usage: make_directory_path <path/to/dir>");
      return;
   end if;

   declare
      Path : String renames Ada.Command_Line.Argument (1);
   begin
      Ada.Directories.Create_Path (Path);
   end;
end Make_Directory_Path;
Task: Make directory path







Python: from errno import EEXIST
from os import mkdir, curdir
from os.path import split, exists

def mkdirp(path, mode=0777):
    head, tail = split(path)
    if not tail:
        head, tail = split(head)
    if head and tail and not exists(head):
        try:
            mkdirp(head, mode)
        except OSError as e:
            
            if e.errno != EEXIST:
                raise
        if tail == curdir:  
            return
    try:
        mkdir(path, mode)
    except OSError as e:
        
        if e.errno != EEXIST:
            raise





Ada: with Ada.Command_Line;
with Ada.Directories;
with Ada.Text_IO;

procedure Make_Directory_Path is
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put_Line ("Usage: make_directory_path <path/to/dir>");
      return;
   end if;

   declare
      Path : String renames Ada.Command_Line.Argument (1);
   begin
      Ada.Directories.Create_Path (Path);
   end;
end Make_Directory_Path;
Task: Make directory path








VB: Module Module1

    Sub Main()
        System.IO.Directory.CreateDirectory("some/where")
    End Sub

End Module




Ada: with Ada.Command_Line;
with Ada.Directories;
with Ada.Text_IO;

procedure Make_Directory_Path is
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put_Line ("Usage: make_directory_path <path/to/dir>");
      return;
   end if;

   declare
      Path : String renames Ada.Command_Line.Argument (1);
   begin
      Ada.Directories.Create_Path (Path);
   end;
end Make_Directory_Path;
Task: Make directory path

C: #include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>

int main (int argc, char **argv) {
    char *str, *s;
    struct stat statBuf;

    if (argc != 2) {
        fprintf (stderr, "usage: %s <path>\n", basename (argv[0]));
        exit (1);
    }
    s = argv[1];
    while ((str = strtok (s, "/")) != NULL) {
        if (str != s) {
            str[-1] = '/';
        }
        if (stat (argv[1], &statBuf) == -1) {
            mkdir (argv[1], 0);
        } else {
            if (! S_ISDIR (statBuf.st_mode)) {
                fprintf (stderr, "couldn't create directory %s\n", argv[1]);
                exit (1);
            }
        }
        s = NULL;
    }
    return 0;
}
Task: Make directory path


C++: #include <filesystem>
#include <iostream>

namespace fs = std::filesystem;

int main(int argc, char* argv[])
{
	if(argc != 2)
	{
		std::cout << "usage: mkdir <path>\n";
		return -1;
	}

	fs::path pathToCreate(argv[1]);

	if (fs::exists(pathToCreate))
		return 0;

	if (fs::create_directories(pathToCreate))
		return 0;
	else
	{
		std::cout << "couldn't create directory: " << pathToCreate.string() << std::endl;
		return -1;
	}
}
Task: Make directory path





Java: import java.io.File;

public interface Test {

    public static void main(String[] args) {
        try {
            File f = new File("C:/parent/test");
            if (f.mkdirs())
                System.out.println("path successfully created");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Task: Make directory path







Python: from errno import EEXIST
from os import mkdir, curdir
from os.path import split, exists

def mkdirp(path, mode=0777):
    head, tail = split(path)
    if not tail:
        head, tail = split(head)
    if head and tail and not exists(head):
        try:
            mkdirp(head, mode)
        except OSError as e:
            
            if e.errno != EEXIST:
                raise
        if tail == curdir:  
            return
    try:
        mkdir(path, mode)
    except OSError as e:
        
        if e.errno != EEXIST:
            raise
Task: Make directory path








VB: Module Module1

    Sub Main()
        System.IO.Directory.CreateDirectory("some/where")
    End Sub

End Module
Task: Make directory path




Go: 	os.MkdirAll("/tmp/some/path/to/dir", 0770)
Task: Make directory path



C#: System.IO.Directory.CreateDirectory(path)