Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Convert the following code from Delphi to Go, ensuring the logic remains intact.
program Walk_a_directory; uses System.IOUtils; var Files: TArray<string>; FileName, Directory: string; begin Directory := TDirectory.GetCurrentDirectory; Files := TDirectory.GetFiles(Directory, '*.*', TSearchOption.soAllDirectories); for FileName in Files do begin Writeln(FileName); end; ...
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Keep all operations the same but rewrite the snippet in C.
defmodule Walk_directory do def recursive(dir \\ ".") do Enum.each(File.ls!(dir), fn file -> IO.puts fname = " if File.dir?(fname), do: recursive(fname) end) end end Walk_directory.recursive
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Keep all operations the same but rewrite the snippet in C#.
defmodule Walk_directory do def recursive(dir \\ ".") do Enum.each(File.ls!(dir), fn file -> IO.puts fname = " if File.dir?(fname), do: recursive(fname) end) end end Walk_directory.recursive
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Produce a language-to-language conversion: from Elixir to C++, same semantics.
defmodule Walk_directory do def recursive(dir \\ ".") do Enum.each(File.ls!(dir), fn file -> IO.puts fname = " if File.dir?(fname), do: recursive(fname) end) end end Walk_directory.recursive
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Port the following code from Elixir to Java with equivalent syntax and logic.
defmodule Walk_directory do def recursive(dir \\ ".") do Enum.each(File.ls!(dir), fn file -> IO.puts fname = " if File.dir?(fname), do: recursive(fname) end) end end Walk_directory.recursive
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Generate a Python translation of this Elixir snippet without changing its computational steps.
defmodule Walk_directory do def recursive(dir \\ ".") do Enum.each(File.ls!(dir), fn file -> IO.puts fname = " if File.dir?(fname), do: recursive(fname) end) end end Walk_directory.recursive
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Translate this program into VB but keep the logic exactly as in Elixir.
defmodule Walk_directory do def recursive(dir \\ ".") do Enum.each(File.ls!(dir), fn file -> IO.puts fname = " if File.dir?(fname), do: recursive(fname) end) end end Walk_directory.recursive
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Write the same algorithm in Go as shown in this Elixir implementation.
defmodule Walk_directory do def recursive(dir \\ ".") do Enum.each(File.ls!(dir), fn file -> IO.puts fname = " if File.dir?(fname), do: recursive(fname) end) end end Walk_directory.recursive
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Transform the following Erlang implementation into C, maintaining the same output and logic.
walk_dir(Path, Pattern) -> filelib:fold_files( Path, Pattern, true, fun(File, Accumulator) -> [File|Accumulator] end, [] )
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Preserve the algorithm and functionality while converting the code from Erlang to C#.
walk_dir(Path, Pattern) -> filelib:fold_files( Path, Pattern, true, fun(File, Accumulator) -> [File|Accumulator] end, [] )
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Preserve the algorithm and functionality while converting the code from Erlang to C++.
walk_dir(Path, Pattern) -> filelib:fold_files( Path, Pattern, true, fun(File, Accumulator) -> [File|Accumulator] end, [] )
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Port the provided Erlang code into Java while preserving the original functionality.
walk_dir(Path, Pattern) -> filelib:fold_files( Path, Pattern, true, fun(File, Accumulator) -> [File|Accumulator] end, [] )
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Write a version of this Erlang function in Python with identical behavior.
walk_dir(Path, Pattern) -> filelib:fold_files( Path, Pattern, true, fun(File, Accumulator) -> [File|Accumulator] end, [] )
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Produce a functionally identical VB code for the snippet given in Erlang.
walk_dir(Path, Pattern) -> filelib:fold_files( Path, Pattern, true, fun(File, Accumulator) -> [File|Accumulator] end, [] )
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Transform the following Erlang implementation into Go, maintaining the same output and logic.
walk_dir(Path, Pattern) -> filelib:fold_files( Path, Pattern, true, fun(File, Accumulator) -> [File|Accumulator] end, [] )
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Write a version of this F# function in C with identical behavior.
open System.IO let rec getAllFiles dir pattern = seq { yield! Directory.EnumerateFiles(dir, pattern) for d in Directory.EnumerateDirectories(dir) do yield! getAllFiles d pattern } getAllFiles "c:\\temp" "*.xml" |> Seq.iter (printfn "%s")
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Transform the following F# implementation into C#, maintaining the same output and logic.
open System.IO let rec getAllFiles dir pattern = seq { yield! Directory.EnumerateFiles(dir, pattern) for d in Directory.EnumerateDirectories(dir) do yield! getAllFiles d pattern } getAllFiles "c:\\temp" "*.xml" |> Seq.iter (printfn "%s")
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Convert this F# block to C++, preserving its control flow and logic.
open System.IO let rec getAllFiles dir pattern = seq { yield! Directory.EnumerateFiles(dir, pattern) for d in Directory.EnumerateDirectories(dir) do yield! getAllFiles d pattern } getAllFiles "c:\\temp" "*.xml" |> Seq.iter (printfn "%s")
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Can you help me rewrite this code in Java instead of F#, keeping it the same logically?
open System.IO let rec getAllFiles dir pattern = seq { yield! Directory.EnumerateFiles(dir, pattern) for d in Directory.EnumerateDirectories(dir) do yield! getAllFiles d pattern } getAllFiles "c:\\temp" "*.xml" |> Seq.iter (printfn "%s")
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Generate an equivalent Python version of this F# code.
open System.IO let rec getAllFiles dir pattern = seq { yield! Directory.EnumerateFiles(dir, pattern) for d in Directory.EnumerateDirectories(dir) do yield! getAllFiles d pattern } getAllFiles "c:\\temp" "*.xml" |> Seq.iter (printfn "%s")
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Produce a language-to-language conversion: from F# to VB, same semantics.
open System.IO let rec getAllFiles dir pattern = seq { yield! Directory.EnumerateFiles(dir, pattern) for d in Directory.EnumerateDirectories(dir) do yield! getAllFiles d pattern } getAllFiles "c:\\temp" "*.xml" |> Seq.iter (printfn "%s")
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Translate the given F# code snippet into Go without altering its behavior.
open System.IO let rec getAllFiles dir pattern = seq { yield! Directory.EnumerateFiles(dir, pattern) for d in Directory.EnumerateDirectories(dir) do yield! getAllFiles d pattern } getAllFiles "c:\\temp" "*.xml" |> Seq.iter (printfn "%s")
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Produce a language-to-language conversion: from Factor to C, same semantics.
USE: io.directories.search "." t [ dup ".factor" tail? [ print ] [ drop ] if ] each-file
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Write a version of this Factor function in C# with identical behavior.
USE: io.directories.search "." t [ dup ".factor" tail? [ print ] [ drop ] if ] each-file
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Can you help me rewrite this code in C++ instead of Factor, keeping it the same logically?
USE: io.directories.search "." t [ dup ".factor" tail? [ print ] [ drop ] if ] each-file
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Generate an equivalent Java version of this Factor code.
USE: io.directories.search "." t [ dup ".factor" tail? [ print ] [ drop ] if ] each-file
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Port the following code from Factor to Python with equivalent syntax and logic.
USE: io.directories.search "." t [ dup ".factor" tail? [ print ] [ drop ] if ] each-file
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Convert this Factor snippet to VB and keep its semantics consistent.
USE: io.directories.search "." t [ dup ".factor" tail? [ print ] [ drop ] if ] each-file
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Please provide an equivalent version of this Factor code in Go.
USE: io.directories.search "." t [ dup ".factor" tail? [ print ] [ drop ] if ] each-file
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Rewrite this program in C while keeping its functionality equivalent to the Forth version.
"*.c" f:rglob
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Generate a C# translation of this Forth snippet without changing its computational steps.
"*.c" f:rglob
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Change the programming language of this snippet from Forth to C++ without modifying what it does.
"*.c" f:rglob
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Convert this Forth block to Java, preserving its control flow and logic.
"*.c" f:rglob
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Write the same code in VB as shown below in Forth.
"*.c" f:rglob
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Produce a functionally identical Go code for the snippet given in Forth.
"*.c" f:rglob
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Ensure the translated C code behaves exactly like the original Groovy snippet.
new File('.').eachFileRecurse { if (it.name =~ /.*\.txt/) println it; }
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Translate this program into C# but keep the logic exactly as in Groovy.
new File('.').eachFileRecurse { if (it.name =~ /.*\.txt/) println it; }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Port the provided Groovy code into C++ while preserving the original functionality.
new File('.').eachFileRecurse { if (it.name =~ /.*\.txt/) println it; }
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Change the programming language of this snippet from Groovy to Java without modifying what it does.
new File('.').eachFileRecurse { if (it.name =~ /.*\.txt/) println it; }
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Maintain the same structure and functionality when rewriting this code in Python.
new File('.').eachFileRecurse { if (it.name =~ /.*\.txt/) println it; }
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Write the same code in VB as shown below in Groovy.
new File('.').eachFileRecurse { if (it.name =~ /.*\.txt/) println it; }
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Translate this program into Go but keep the logic exactly as in Groovy.
new File('.').eachFileRecurse { if (it.name =~ /.*\.txt/) println it; }
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Translate the given Haskell code snippet into C without altering its behavior.
import System.Environment import System.Directory import System.FilePath.Find search pat = find always (fileName ~~? pat) main = do [pat] <- getArgs dir <- getCurrentDirectory files <- search pat dir mapM_ putStrLn files
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Translate this program into C# but keep the logic exactly as in Haskell.
import System.Environment import System.Directory import System.FilePath.Find search pat = find always (fileName ~~? pat) main = do [pat] <- getArgs dir <- getCurrentDirectory files <- search pat dir mapM_ putStrLn files
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Convert this Haskell block to C++, preserving its control flow and logic.
import System.Environment import System.Directory import System.FilePath.Find search pat = find always (fileName ~~? pat) main = do [pat] <- getArgs dir <- getCurrentDirectory files <- search pat dir mapM_ putStrLn files
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Produce a functionally identical Java code for the snippet given in Haskell.
import System.Environment import System.Directory import System.FilePath.Find search pat = find always (fileName ~~? pat) main = do [pat] <- getArgs dir <- getCurrentDirectory files <- search pat dir mapM_ putStrLn files
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Write the same code in Python as shown below in Haskell.
import System.Environment import System.Directory import System.FilePath.Find search pat = find always (fileName ~~? pat) main = do [pat] <- getArgs dir <- getCurrentDirectory files <- search pat dir mapM_ putStrLn files
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Generate a VB translation of this Haskell snippet without changing its computational steps.
import System.Environment import System.Directory import System.FilePath.Find search pat = find always (fileName ~~? pat) main = do [pat] <- getArgs dir <- getCurrentDirectory files <- search pat dir mapM_ putStrLn files
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Ensure the translated Go code behaves exactly like the original Haskell snippet.
import System.Environment import System.Directory import System.FilePath.Find search pat = find always (fileName ~~? pat) main = do [pat] <- getArgs dir <- getCurrentDirectory files <- search pat dir mapM_ putStrLn files
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Can you help me rewrite this code in C instead of J, keeping it the same logically?
require 'dir' >{."1 dirtree '*.html'
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Generate a C# translation of this J snippet without changing its computational steps.
require 'dir' >{."1 dirtree '*.html'
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Change the programming language of this snippet from J to C++ without modifying what it does.
require 'dir' >{."1 dirtree '*.html'
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Convert this J snippet to Java and keep its semantics consistent.
require 'dir' >{."1 dirtree '*.html'
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Convert this J block to Python, preserving its control flow and logic.
require 'dir' >{."1 dirtree '*.html'
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Write the same algorithm in VB as shown in this J implementation.
require 'dir' >{."1 dirtree '*.html'
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Transform the following J implementation into Go, maintaining the same output and logic.
require 'dir' >{."1 dirtree '*.html'
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Port the provided Julia code into C while preserving the original functionality.
rootpath = "/home/user/music" pattern = r".mp3$" for (root, dirs, files) in walkdir(rootpath) for file in files if occursin(pattern, file) println(file) end end end
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Can you help me rewrite this code in C# instead of Julia, keeping it the same logically?
rootpath = "/home/user/music" pattern = r".mp3$" for (root, dirs, files) in walkdir(rootpath) for file in files if occursin(pattern, file) println(file) end end end
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Write a version of this Julia function in C++ with identical behavior.
rootpath = "/home/user/music" pattern = r".mp3$" for (root, dirs, files) in walkdir(rootpath) for file in files if occursin(pattern, file) println(file) end end end
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Produce a functionally identical Java code for the snippet given in Julia.
rootpath = "/home/user/music" pattern = r".mp3$" for (root, dirs, files) in walkdir(rootpath) for file in files if occursin(pattern, file) println(file) end end end
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Keep all operations the same but rewrite the snippet in Python.
rootpath = "/home/user/music" pattern = r".mp3$" for (root, dirs, files) in walkdir(rootpath) for file in files if occursin(pattern, file) println(file) end end end
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Port the following code from Julia to VB with equivalent syntax and logic.
rootpath = "/home/user/music" pattern = r".mp3$" for (root, dirs, files) in walkdir(rootpath) for file in files if occursin(pattern, file) println(file) end end end
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Can you help me rewrite this code in Go instead of Julia, keeping it the same logically?
rootpath = "/home/user/music" pattern = r".mp3$" for (root, dirs, files) in walkdir(rootpath) for file in files if occursin(pattern, file) println(file) end end end
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Convert the following code from Lua to C, ensuring the logic remains intact.
local lfs = require("lfs") function find(self, fn) return coroutine.wrap(function() for f in lfs.dir(self) do if f ~= "." and f ~= ".." then local _f = self .. "/" .. f if not fn or fn(_f) then coroutine.yield(_f) end if lfs.attributes(_f, "mode") == "directory"...
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Translate this program into C# but keep the logic exactly as in Lua.
local lfs = require("lfs") function find(self, fn) return coroutine.wrap(function() for f in lfs.dir(self) do if f ~= "." and f ~= ".." then local _f = self .. "/" .. f if not fn or fn(_f) then coroutine.yield(_f) end if lfs.attributes(_f, "mode") == "directory"...
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Write the same algorithm in C++ as shown in this Lua implementation.
local lfs = require("lfs") function find(self, fn) return coroutine.wrap(function() for f in lfs.dir(self) do if f ~= "." and f ~= ".." then local _f = self .. "/" .. f if not fn or fn(_f) then coroutine.yield(_f) end if lfs.attributes(_f, "mode") == "directory"...
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Change the programming language of this snippet from Lua to Java without modifying what it does.
local lfs = require("lfs") function find(self, fn) return coroutine.wrap(function() for f in lfs.dir(self) do if f ~= "." and f ~= ".." then local _f = self .. "/" .. f if not fn or fn(_f) then coroutine.yield(_f) end if lfs.attributes(_f, "mode") == "directory"...
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Write the same code in Python as shown below in Lua.
local lfs = require("lfs") function find(self, fn) return coroutine.wrap(function() for f in lfs.dir(self) do if f ~= "." and f ~= ".." then local _f = self .. "/" .. f if not fn or fn(_f) then coroutine.yield(_f) end if lfs.attributes(_f, "mode") == "directory"...
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Generate a VB translation of this Lua snippet without changing its computational steps.
local lfs = require("lfs") function find(self, fn) return coroutine.wrap(function() for f in lfs.dir(self) do if f ~= "." and f ~= ".." then local _f = self .. "/" .. f if not fn or fn(_f) then coroutine.yield(_f) end if lfs.attributes(_f, "mode") == "directory"...
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Preserve the algorithm and functionality while converting the code from Lua to Go.
local lfs = require("lfs") function find(self, fn) return coroutine.wrap(function() for f in lfs.dir(self) do if f ~= "." and f ~= ".." then local _f = self .. "/" .. f if not fn or fn(_f) then coroutine.yield(_f) end if lfs.attributes(_f, "mode") == "directory"...
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Preserve the algorithm and functionality while converting the code from Mathematica to C.
FileNames["*"] FileNames["*.png", $RootDirectory] FileNames["*", {"*"}, Infinity]
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Translate this program into C# but keep the logic exactly as in Mathematica.
FileNames["*"] FileNames["*.png", $RootDirectory] FileNames["*", {"*"}, Infinity]
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Ensure the translated C++ code behaves exactly like the original Mathematica snippet.
FileNames["*"] FileNames["*.png", $RootDirectory] FileNames["*", {"*"}, Infinity]
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Change the following Mathematica code into Java without altering its purpose.
FileNames["*"] FileNames["*.png", $RootDirectory] FileNames["*", {"*"}, Infinity]
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Port the provided Mathematica code into Python while preserving the original functionality.
FileNames["*"] FileNames["*.png", $RootDirectory] FileNames["*", {"*"}, Infinity]
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Port the following code from Mathematica to VB with equivalent syntax and logic.
FileNames["*"] FileNames["*.png", $RootDirectory] FileNames["*", {"*"}, Infinity]
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Keep all operations the same but rewrite the snippet in Go.
FileNames["*"] FileNames["*.png", $RootDirectory] FileNames["*", {"*"}, Infinity]
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Translate the given MATLAB code snippet into C without altering its behavior.
function walk_a_directory_recursively(d, pattern) f = dir(fullfile(d,pattern)); for k = 1:length(f) fprintf(' end; f = dir(d); n = find([f.isdir]); for k=n(:)' if any(f(k).name~='.') walk_a_directory_recursively(fullfile(d,f(k).name), pattern); end; end; end;
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Rewrite the snippet below in C# so it works the same as the original MATLAB code.
function walk_a_directory_recursively(d, pattern) f = dir(fullfile(d,pattern)); for k = 1:length(f) fprintf(' end; f = dir(d); n = find([f.isdir]); for k=n(:)' if any(f(k).name~='.') walk_a_directory_recursively(fullfile(d,f(k).name), pattern); end; end; end;
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Produce a functionally identical C++ code for the snippet given in MATLAB.
function walk_a_directory_recursively(d, pattern) f = dir(fullfile(d,pattern)); for k = 1:length(f) fprintf(' end; f = dir(d); n = find([f.isdir]); for k=n(:)' if any(f(k).name~='.') walk_a_directory_recursively(fullfile(d,f(k).name), pattern); end; end; end;
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Translate this program into Java but keep the logic exactly as in MATLAB.
function walk_a_directory_recursively(d, pattern) f = dir(fullfile(d,pattern)); for k = 1:length(f) fprintf(' end; f = dir(d); n = find([f.isdir]); for k=n(:)' if any(f(k).name~='.') walk_a_directory_recursively(fullfile(d,f(k).name), pattern); end; end; end;
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Write a version of this MATLAB function in Python with identical behavior.
function walk_a_directory_recursively(d, pattern) f = dir(fullfile(d,pattern)); for k = 1:length(f) fprintf(' end; f = dir(d); n = find([f.isdir]); for k=n(:)' if any(f(k).name~='.') walk_a_directory_recursively(fullfile(d,f(k).name), pattern); end; end; end;
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Convert the following code from MATLAB to VB, ensuring the logic remains intact.
function walk_a_directory_recursively(d, pattern) f = dir(fullfile(d,pattern)); for k = 1:length(f) fprintf(' end; f = dir(d); n = find([f.isdir]); for k=n(:)' if any(f(k).name~='.') walk_a_directory_recursively(fullfile(d,f(k).name), pattern); end; end; end;
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Produce a functionally identical Go code for the snippet given in MATLAB.
function walk_a_directory_recursively(d, pattern) f = dir(fullfile(d,pattern)); for k = 1:length(f) fprintf(' end; f = dir(d); n = find([f.isdir]); for k=n(:)' if any(f(k).name~='.') walk_a_directory_recursively(fullfile(d,f(k).name), pattern); end; end; end;
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Change the programming language of this snippet from Nim to C without modifying what it does.
import os, re for file in walkDirRec "/": if file.match re".*\.mp3": echo file
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Write a version of this Nim function in C# with identical behavior.
import os, re for file in walkDirRec "/": if file.match re".*\.mp3": echo file
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Port the provided Nim code into C++ while preserving the original functionality.
import os, re for file in walkDirRec "/": if file.match re".*\.mp3": echo file
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Transform the following Nim implementation into Java, maintaining the same output and logic.
import os, re for file in walkDirRec "/": if file.match re".*\.mp3": echo file
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Rewrite this program in Python while keeping its functionality equivalent to the Nim version.
import os, re for file in walkDirRec "/": if file.match re".*\.mp3": echo file
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Produce a language-to-language conversion: from Nim to VB, same semantics.
import os, re for file in walkDirRec "/": if file.match re".*\.mp3": echo file
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Change the programming language of this snippet from Nim to Go without modifying what it does.
import os, re for file in walkDirRec "/": if file.match re".*\.mp3": echo file
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Generate an equivalent C version of this OCaml code.
#!/usr/bin/env ocaml #load "unix.cma" #load "str.cma" open Unix let walk_directory_tree dir pattern = let re = Str.regexp pattern in let select str = Str.string_match re str 0 in let rec walk acc = function | [] -> (acc) | dir::tail -> let contents = Array.to_list (Sys.readdir dir) in let conten...
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Can you help me rewrite this code in C# instead of OCaml, keeping it the same logically?
#!/usr/bin/env ocaml #load "unix.cma" #load "str.cma" open Unix let walk_directory_tree dir pattern = let re = Str.regexp pattern in let select str = Str.string_match re str 0 in let rec walk acc = function | [] -> (acc) | dir::tail -> let contents = Array.to_list (Sys.readdir dir) in let conten...
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...
Write a version of this OCaml function in C++ with identical behavior.
#!/usr/bin/env ocaml #load "unix.cma" #load "str.cma" open Unix let walk_directory_tree dir pattern = let re = Str.regexp pattern in let select str = Str.string_match re str 0 in let rec walk acc = function | [] -> (acc) | dir::tail -> let contents = Array.to_list (Sys.readdir dir) in let conten...
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (recursive_directory_iterator iter(current_dir), end; iter != end; ++iter) { std::string name = iter->path(...
Rewrite this program in Java while keeping its functionality equivalent to the OCaml version.
#!/usr/bin/env ocaml #load "unix.cma" #load "str.cma" open Unix let walk_directory_tree dir pattern = let re = Str.regexp pattern in let select str = Str.string_match re str 0 in let rec walk acc = function | [] -> (acc) | dir::tail -> let contents = Array.to_list (Sys.readdir dir) in let conten...
import java.io.File; public class MainEntry { public static void main(String[] args) { walkin(new File("/home/user")); } public static void walkin(File dir) { String pattern = ".mp3"; File listFile[] = dir.listFiles(); if (listFile != null) { ...
Produce a functionally identical Python code for the snippet given in OCaml.
#!/usr/bin/env ocaml #load "unix.cma" #load "str.cma" open Unix let walk_directory_tree dir pattern = let re = Str.regexp pattern in let select str = Str.string_match re str 0 in let rec walk acc = function | [] -> (acc) | dir::tail -> let contents = Array.to_list (Sys.readdir dir) in let conten...
from pathlib import Path for path in Path('.').rglob('*.*'): print(path)
Write the same code in VB as shown below in OCaml.
#!/usr/bin/env ocaml #load "unix.cma" #load "str.cma" open Unix let walk_directory_tree dir pattern = let re = Str.regexp pattern in let select str = Str.string_match re str 0 in let rec walk acc = function | [] -> (acc) | dir::tail -> let contents = Array.to_list (Sys.readdir dir) in let conten...
Sub printFiles(parentDir As FolderItem, pattern As String) For i As Integer = 1 To parentDir.Count If parentDir.Item(i).Directory Then printFiles(parentDir.Item(i), pattern) Else Dim rg as New RegEx Dim myMatch as RegExMatch rg.SearchPattern = pattern myMatch = rg.search(parentDi...
Convert this OCaml block to Go, preserving its control flow and logic.
#!/usr/bin/env ocaml #load "unix.cma" #load "str.cma" open Unix let walk_directory_tree dir pattern = let re = Str.regexp pattern in let select str = Str.string_match re str 0 in let rec walk acc = function | [] -> (acc) | dir::tail -> let contents = Array.to_list (Sys.readdir dir) in let conten...
package main import ( "fmt" "os" "path/filepath" ) func VisitFile(fp string, fi os.FileInfo, err error) error { if err != nil { fmt.Println(err) return nil } if fi.IsDir() { return nil } matched, err := filepath.Match("*.mp3", fi.Name()) if err != n...
Translate the given Perl code snippet into C without altering its behavior.
use File::Find qw(find); my $dir = '.'; my $pattern = 'foo'; my $callback = sub { print $File::Find::name, "\n" if /$pattern/ }; find $callback, $dir;
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> #include <regex.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <err.h> enum { WALK_OK = 0, WALK_BADPATTERN, WALK_NAMETOOLONG, WALK_BADIO, }; #define WS_NONE 0 #define WS_RECURSIVE (1 << 0) #define WS_DEFAU...
Write the same algorithm in C# as shown in this Perl implementation.
use File::Find qw(find); my $dir = '.'; my $pattern = 'foo'; my $callback = sub { print $File::Find::name, "\n" if /$pattern/ }; find $callback, $dir;
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace RosettaRecursiveDirectory { class Program { static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern) { var directoryStack = new Stack<DirectoryInfo>(); ...