Code repeater project [C# ]


If you've been following me for a while and you've read some of the articles or comments I wrote, you might know that I tried to learn how to code many times in the past.

I tried web development for a while, then Python, then for a very brief amount of time Java, and then C#.

I hate the way web development works, because you have to keep track of both HTML and CSS at the same time, then implement JavaScript in-between and make sure you don't break anything, which, for me, was a pain to deal with.

Python was fun, but I was never capable of finding cool projects to work on (too many choices).

Java... let's not talk about Java.

And finally, C#, which I tried learning by applying a "strategy" I read about in Antifragile , a book written byNassim Nicholas Taleb which, to an extent, promotes the idea of starting to work on something directly, instead of wasting too much of your time with learning.

To my surprise, the strategy worked, and I managed to learn more C# in a few months than I expected. Then I eventually stopped learning as I started doing other things.

However, I found myself going back to C# whenever I wanted to do any type of coding work, especially when I needed to automate certain things. For some reason, I find it much easier to understand than other languages.

The first project I created using C#, without following a tutorial, was a folder creator, a small program that allows me to pick a directory where I want all the new folders to be, then type in a "name scheme", and then decide how many folders I need.

It was fun to make, and it can be quite useful whenever I need to create a bunch of folders quickly.

Aside from that project, I worked on other small things here and there, including the thing I built today, which is another "small" program that allows me to add text that changes next to static text.

It sounds confusing, so let me explain.

Around two years ago I bought a Samsung A50 from an online store, since I needed a new phone, and I was quite happy with it until, for some reason, the phone started to freeze and restart itself whenever it felt like it.

I couldn't figure out the problem, and I didn't have the time to send it back to the store, so I just used it like that... until it decided to get stuck in a "booting loop". Basically the phone kept restarting without even turning on completely.

Since I didn't have time to deal with it, I just switched to an older model, a J6, and forgot about the A50 until recently. I somehow managed to get into the recovery mode and reset the phone completely, which allowed it to finally boot.

However, the phone kept crashing once in a while, even though I sometimes never installed anything on it.

Frustrated, I started doing some research online, and besides custom ROMs, rooting and all kind of other things, I found an interesting video that showed me how to uninstall the default apps that come with Samsung phones.

After doing everything from the video and deleting around 50 default apps, my phone surprisingly stopped crashing and restarting, and even began working a lot better than when I purchased it. Plus, the battery now lasts for around a week, without intense use, rather than 2-3 days.

Now, while the process of deleting all those apps is a simple one, it does require quite a lot of typing. You have to write the code of each individual app + the code for deleting the apps, which is the same all the time.


It took me around 45 minutes to finish the entire process, and when I was done, I made the mistake of disabling another app, this time a system app, and that made my phone unusable.

So, I had to wipe everything again, start a new clean installation which, annoyingly, also brought back all the apps I deleted.

Luckily for me, I, for some reason, copied all the 50 commands that I wrote, by hand, into a file once I was done with the process the first time. So, the second time, all I had to do was to paste them all into the command line, which allowed me to uninstall every app without having to write everything again.

Now, as you can see from the image above, each command has two parts:

  • one that never changes : pm uninstall -k --user 0
  • one that always changes:

Having to paste the command that never changes in front of the one that does every time I uninstall an app is annoying and takes time, so, I thought it would be useful to have some sort of a program that would allow me to simply type in the command that never changes once, then type in all the commands that do change, and then have the program put them together as many times as needed, then export all the commands into a text file where I can copy everything without any effort.

Now, I'm sure that this type of program already exists out there, but I had no idea how to search for it, and it seemed like a good exercise for me to do in order to remember some of the C# I forgot.

So, I started to work.

The concept was actually quite simple:

  1. The program would ask the user for the location of the text file where all the commands would be exported

  2. Then it would ask for the static code that would be repeated

  3. Then it would allow the user to add the commands that would change, one by one

  4. At the end, the program would export the full commands into a notepad file.

After I finished thinking about how the program would work, I started coding, and in around two hours, I managed to complete the project.

I didn't upload it anywhere, and I won't do it soon, first because I doubt anyone cares and second, because there are still things to be fixed. Besides, the code only works in the console, and only if you create the folder and the text file in any other partition than C, because I couldn't figure out how to give my program administrator privileges to edit a text file on my desktop.

This is how everything looks like after running the program:


Anyway, that's something I did today and thought I'd share it with you.

I will post the code on GitHub eventually, once it's good enough and I fix some things that are wrong with it.

It was a great way for me to get back into C# and actually create something that I can use, both whenever I need to uninstall a bunch of apps from one of my Samsung phones, or for any other task that requires both static and dynamic text.

Thank you for reading! :)

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!