Question based on recursion in Scala

You have one directory structure , in the directory there are some folders and some files
Now in file and directory, there are some name “MOHAN” then we have to replace all of them by “AMIT”…in all folder and file within that directoryexample - change abc_scala change to abc_python …like this

My approach - go step to step
insde folder there may be many files.
we have to recursively go step by step
if it is file we have to recursively change the names
then go inside each folder reursively

Please advise some other approach to solve this or any similar kind of use case pseudo c

I would create some kind of lazy collection of Files that would manage the recursive directory traversal , the nio package has some useful things for this; personally, I would go with fs2 Stream

Then I would just open each file, and perform the string replace and write again. has a .listFiles() to get the contents of a directory. From there partitioning with _.isDirectory will give you files to change and directories to recurse into.

1 Like