How do I copy a list of file names in a directory or folder to a text file? I've seen this answer asked many times on the web. And many times the asker is directed to sites offering software to do this. However, this can be done quickly and easily with a few keystrokes at the command prompt. Here is how to do it in windows.
-Open the command prompt. It is usually located in Start>Programs>Accessories, or try searching windows for "cmd".
-Now, navigate to the directory using the 'cd' command. For example, to get to the Documents folder, when you open the command prompt you should be in your home directory.
C:\Users\YourUsernameHere>
To get to the Documents folder, you would enter
"cd Documents" (without the quotes).
Do this until you get to the folder that you want.
-Once you have navigated to the directory you want to list, type "dir" then ">", then the text file that you want to save the list to, including the .txt extension. For example:
"dir >list.txt"
Will create a new text file named list.txt in the same directory that you chose.
**WARNING** If you choose the name of a file that already exists, it will be overwritten without prompting!
You can also use options when creating the list. You may have noticed that the list included the date modified, whether the file was a directory, and the file size. Here are some options that you can use:
/b lists only the file names (including extension), but not dates and file sizes.
/s list subfolders
/a show all files including hidden and system files
/o sort alphabetically
/d sort by date
If you want to append the list to the end of a text file instead of completely overwriting the file, use ">>" instead ">".
If your directory name has spaces, you may need to enclose the file path with quotes.
You can also have the text file created in a different location, while using the full file path of the directory you want listed.
Putting this all together, say I want a list of some pictures I have in a folder called "Beach Pics" (notice the space in the name), with file names only, and sorted alphabetically. AND I want to create the text file on my Desktop so I can get to it quickly.
Open command prompt. This is shown:
C:\Users\Mike>
Navigate to the Desktop to create the file there by typing:
cd Desktop
Press Enter.
C:\Users\Mike\Desktop>
Now create the list by typing all of the following:
dir "C:\Users\Mike\Pictures\Beach Pics" /o /b >list.txt
Press Enter.
To understand what is going on here, the "dir" command lists all files in either the current directory, or the directory entered, if any. The ">" command simply outputs this directory list to a file, in this case our text file.
**Disclaimer:
My blog contains content that may be objectionable. Some of the posts in this blog may contain strong language or (because of my religious and personal views) may be offensive to some readers. In the future I may separate my programming posts from personal posts, but for now they are all contained in this blog. I should not have to even mention this, however some readers may be looking at my blog for programming help, therefore I am giving an advanced warning. All posts with material that may be offensive contain 'Objectionable material' at the end of the post title. If you see a post with "Objectionable material" in the title, and you are closed-minded or think that you may get queasy, don't fucking read it.
My blog contains content that may be objectionable. Some of the posts in this blog may contain strong language or (because of my religious and personal views) may be offensive to some readers. In the future I may separate my programming posts from personal posts, but for now they are all contained in this blog. I should not have to even mention this, however some readers may be looking at my blog for programming help, therefore I am giving an advanced warning. All posts with material that may be offensive contain 'Objectionable material' at the end of the post title. If you see a post with "Objectionable material" in the title, and you are closed-minded or think that you may get queasy, don't fucking read it.
Sunday, August 23, 2009
Friday, August 21, 2009
SSCCEs and getting help by providing test code
SSCCE: Short, Self Contained, Compilable and Executeable
When debugging a program, you may run into problems that you simply cannot find on your own. If you have tried using a debugger, and have gone over your code many times looking for the problem, it may be time to give in and ask for help. The first thing to do before asking your question is to create an SSCCE. This is a small simple test program that can be compiled and run by someone else to help find the bug. You should make this test case as simple as possible. Remove any code that is not related to the problem. Remove any GUI components, methods, variables and anything else that is not related to the problem. You want the code to be clean, readable, and short. The test case must also be compilable and executeable. There is no point in posting an SSCCE if the person trying to help cannot run the code to look for the problem. Be sure that the problem is in the test case. It can be a real pain to create a test case and spend the time to remove sections of code. But if you remove small sections, such as one method at a time, then try running the code before removing another section, you will find that 9 times out of 10 you will find the bug yourself. You can quickly narrow down and find a bug yourself this way, just by creating an SSCCE. If you have trimmed down your code and still cannot find the problem, post the code into a site like www.pastebin.com and then copy the url to add with your question. Be polite, clear, and concise when you ask your question. Tell them what is happening, what you have tried while debugging, and provide the SSCCE url. Don't be rude or demand help, as most of the people where you go for help are volunteers do not have to help you, however they are offering their personal time to help others. They also may not give you an exact answer, but will point you in the direction to find the answer yourself. This way you will learn why you have the bug and will be able to prevent it from happening again in the future.
When debugging a program, you may run into problems that you simply cannot find on your own. If you have tried using a debugger, and have gone over your code many times looking for the problem, it may be time to give in and ask for help. The first thing to do before asking your question is to create an SSCCE. This is a small simple test program that can be compiled and run by someone else to help find the bug. You should make this test case as simple as possible. Remove any code that is not related to the problem. Remove any GUI components, methods, variables and anything else that is not related to the problem. You want the code to be clean, readable, and short. The test case must also be compilable and executeable. There is no point in posting an SSCCE if the person trying to help cannot run the code to look for the problem. Be sure that the problem is in the test case. It can be a real pain to create a test case and spend the time to remove sections of code. But if you remove small sections, such as one method at a time, then try running the code before removing another section, you will find that 9 times out of 10 you will find the bug yourself. You can quickly narrow down and find a bug yourself this way, just by creating an SSCCE. If you have trimmed down your code and still cannot find the problem, post the code into a site like www.pastebin.com and then copy the url to add with your question. Be polite, clear, and concise when you ask your question. Tell them what is happening, what you have tried while debugging, and provide the SSCCE url. Don't be rude or demand help, as most of the people where you go for help are volunteers do not have to help you, however they are offering their personal time to help others. They also may not give you an exact answer, but will point you in the direction to find the answer yourself. This way you will learn why you have the bug and will be able to prevent it from happening again in the future.
Thursday, August 20, 2009
Learning the Java programming language
I have read many books on Java when I first got into computer programming. Most of the books I read had good information, but none of it really made much sense. From these books I learned how to write some code, but when it came time for me to actual create a class or method on my own, I had no idea where to start. While searching Google I came across a free course offered by Stanford. I highly recommend this for anyone wanting to learn Java programming. This is a full course with about 25 videos, each about an hour long. They give real hands-on learning, and all the hand outs and documentation is also provided. I picked up Java very quickly with this course, because it teaches the actual methodology and how to think and design your application when you begin programming. You can find these videos by either going to the Stanford University website at www.stanford.edu or by searching YouTube using keywords like "Programming methodology Stanford". Once you have watched the videos and have a basic understanding of Java, read the Java APIs from the Sun website. Google also provides many results for learning Java. If you get stuck on a problem and absolutely cannot solve it yourself, there are many places to go for help, including the ##java channel on the freenode irc network. Good luck and happy programming!
Labels:
api,
java,
methodology,
programming,
stanford,
sun
Welcome to my blog!
This is my first blog. I am 23 years old. At the age of around 13 I began learning HTML to create a simple browser homepage. I was amazed by the fact that I could create anything with the use of some text, and began slowly expanding my knowledge base from here. I spent a few years hacking GUI's, modifying anything and everything I could by modifying CSS code and editing images with Photoshop. Within the last year I have really gotten into programming. I watched the free "Programming Methodology" course posted by Stanford, and have started writing Java. I am currently working on a simple weather application that gets weather observations and warnings from the National Weather Services' NOAA database. Once I have some intermediate JAVA experience, I plan to move on to C++ and then some other languages. My ultimate goal is to get a Bachelor degree in Computer Sciences and begin a career toward Artificial Intelligence.
Subscribe to:
Posts (Atom)