Skip to main content

Command Palette

Search for a command to run...

Worked example - Creating a C# class for each file in a folder

Published
1 min read
Worked example - Creating a C# class for each file in a folder

I recently needed to create a C# class for each file in a folder. This was a one-off job, but there were a large number of files in the folder. How would you approach doing this?

I used the command line to list the files, using the dir command. I piped the result to the clip command so the list of files was put on my clipboard rather than the screen.

dir | clip

I then pasted this into my IDE so I could use its multiline editing tool. (I use JetBrains Rider but I'm sure multiline editing is common functionality in most IDEs.) This made it quick and easy to remove the data I didn't need, and turn each filename into a class. I then used Rider to split the classes out into separate files, as is idiomatic in C#.

This was a quick job in the end, and it brought home the value of being familiar and comfortable with the tools at your disposal.

Worked examples

Part 6 of 12

Descriptions of how specific situations have unfolded in real-world programming I've done. Aims to provide insights into the reality of a programmer's work and learn lessons from these occasions.

Up next

Worked example - Writing better commit messages

Adding references and explanations to commit messages to help other developers understand your reasoning

More from this blog

T

Tim talks tech

76 posts