How Do I Think Logically When Programming?

Upload and start working with your PDF documents.
No downloads required

How To Write on PDF Online?

Upload & Edit Your PDF Document
Save, Download, Print, and Share
Sign & Make It Legally Binding

How do I think logically when programming? I have folders that contain mp4, text, pdf, doc, mp3 files and I would like to separate them. I can write Ruby code, but it’s the logic that kills me. I've worked on this problem for 3 weeks.

I think you’re doing it the right way. You’re splitting your task into sub-tasks (with pseudocode or anything else), but I guess you need to split even more. Let’s consider a simple version of your program. It runs on the console, which means it doesn’t include any graphic user interface like buttons, labels, or text fields. You take inputs only from text files. Firstly you want to ask the user where to find the files to sort. Create a text file with a name like input_dir.txt and write your path of the original files. You could support only one line in this file (assuming on Windows). D.\Documents\MyMessyFolder You read this only line from this file in your code into a variable, such as messy_dir. Don’t mind whether it’s a legal path at first. Secondly, you want to sort the files by their extensions. But before that, you have to get a list of all the files under messy_dir. Find an API to list files under some directory. Better be a recursive one, which means it would list files under sub-directories if any. Put the result into a list (or an array, or something else) named messy_file_paths. Now the time to consider which extensions you want to support. For example, you want to sort only MP3, PDF and TXT files into separate folders named music, docs, pure_texts, and put all the others into another folder named other. You could create another text file named, for example, file_types.txt, whose contents look like. other mp3 music pdf docs txt pure_texts The first line contains only one element, which is the subfolder name for all miscellaneous files. The other lines contains a pair of strings, in each of which the former is the file extension and the latter is the target subfolder name. You need to read this file, and properly store the information. For example, you could use a variable called misc_subfolder_name to store ‘other’, and then a dictionary called exts_to_subfolder_names to store the other things, where the file extension is the key and the subfolder name is the value. You then ask the user where to save the files. Use another text file like our first one and read it to a variable target_root_path. Now, enumerate your messy_file_paths, and for each, check the file extension and use exts_to_subfolder_names with target_root_path to build the full path of the target subfolders. Create these folders (if needed) and copy (safer than move) the file into the folder. Your final step can be done by looking at whether the files appear in the new location. So far I’ve described a simple way to extend your pseudocode into more detailed logic flow. Can you go on from here? Debugging Tips. Generally you won’t be able to run your program correctly the first time. It takes lots of time to debug your program to make it work as expected. A simple way to debug a program is to print things everywhere in your program. For example, you read a line from a file into a variable, and then you could print it so that you can check whether it’s correct when your program runs. Others ways of debugging a program include the break point technique, which you don’t need for now, I guess. Knowledge points. Variables. strings, dictionaries and maybe other types. Usage of collections (lists and dictionaries) and loops. File IO. Reading from a text file, copying/moving files, listing files under a folder, creating new folders, etc. Standard IO. Print stuff to the standard output. …… [Hope this long stuff helps]

Customers love our service for intuitive functionality



46 votes

Write on PDF: All You Need to Know

If you have any questions please post them in the comments below! And if you like it, share it!! :).

What Our Customers Say

Deborah W.
Deborah W.
I corrected a mistake in my form and replaced it with the right information. It took a few minutes only! Thanks a lot!
James S.
James S.
The process of PDF correction has never been so easy. I’ve managed to create a new document faster than ever before!
William G.
William G.
It was really easy to fill out my PDF document and add a signature to it! This is a great service! I recommend it to you!
Denis B.
Denis B.
I edited the document with my mobile phone. It was fast and, as a result, I’ve got a professional-looking document.

Supporting Forms

Submit important papers on the go with the number one online document management solution. Use our web-based app to edit your PDFs without effort. We provide our customers with an array of up-to-date tools accessible from any Internet-connected device. Upload your PDF document to the editor. Browse for a file on your device or add it from an online location. Insert text, images, fillable fields, add or remove pages, sign your PDFs electronically, all without leaving your desk.