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

Easy-to-use PDF software

review-platform review-platform review-platform review-platform review-platform

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]

PDF documents can be cumbersome to edit, especially when you need to change the text or sign a form. However, working with PDFs is made beyond-easy and highly productive with the right tool.

How to Write On PDF with minimal effort on your side:

  1. Add the document you want to edit — choose any convenient way to do so.
  2. Type, replace, or delete text anywhere in your PDF.
  3. Improve your text’s clarity by annotating it: add sticky notes, comments, or text blogs; black out or highlight the text.
  4. Add fillable fields (name, date, signature, formulas, etc.) to collect information or signatures from the receiving parties quickly.
  5. Assign each field to a specific recipient and set the filling order as you Write On PDF.
  6. Prevent third parties from claiming credit for your document by adding a watermark.
  7. Password-protect your PDF with sensitive information.
  8. Notarize documents online or submit your reports.
  9. Save the completed document in any format you need.

The solution offers a vast space for experiments. Give it a try now and see for yourself. Write On PDF with ease and take advantage of the whole suite of editing features.

Customers love our service for intuitive functionality

4.5

satisfied

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!! :).