-
August 25th, 2008, 08:33 PM
#1
Need a simple program!
Hi all,
It's been some time since I last touched programming, but if anyone is free, here's a simple request which I'm sure most programmers can churn out in 5 mins or less.
Basically, I need a program that will loop through a folder and get the names of all the files in that folder, and output them in a list box or text box.
To make things even simpler, all the user need is to place the program in the same folder, click a button and and it will loop through all the files and get the file names etc.
Or if anyone has a link to a program like that, let me know as well.
Thanks!
Xeon.
"Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria
"I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria
-
August 25th, 2008, 10:38 PM
#2
Re: Need a simple program!
Your right - it's simple. I can guide you through it in 6 easy steps, and you don't have to even fire up your favorite code generator....
Please note that these instructions are tailored for Windows users...
1) Open a command window
2) Navigate to the desired folder
3) type 'dir > filename.txt' (insert the filename of your choice here)
4) hit Enter
5) type 'notepad filename.txt' (same filename as above)
6) View the list you just created in all it's glory in the Notepad textbox.
If you really want to get fancy, you can add a 7th step, and copy the above steps into a batch file :-)
Enjoy!!
-
August 25th, 2008, 11:18 PM
#3
Re: Need a simple program!
Here's how you find files in the directory that this .exe resides in:
Code:
#include <windows.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv)
{
CHAR szDir[MAX_PATH];
GetCurrentDirectoryA(sizeof(szDir), szDir);
printf("Path: %s\n\n", szDir);
strcat(szDir, "\\*");
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(szDir, &ffd);
do
{
if(!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
LARGE_INTEGER filesize;
filesize.LowPart = ffd.nFileSizeLow;
filesize.HighPart = ffd.nFileSizeHigh;
printf("Name: %s\t\tSize: %ld\n", ffd.cFileName, filesize.QuadPart);
}
}
while(FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
puts("\nOperation Complete.");
getchar();
return 0;
}
-
August 25th, 2008, 11:52 PM
#4
Re: Need a simple program!
Originally Posted by Xeon
Hi all,
It's been some time since I last touched programming, but if anyone is free, here's a simple request which I'm sure most programmers can churn out in 5 mins or less.
Basically, I need a program that will loop through a folder and get the names of all the files in that folder, and output them in a list box or text box.
To make things even simpler, all the user need is to place the program in the same folder, click a button and and it will loop through all the files and get the file names etc.
Or if anyone has a link to a program like that, let me know as well.
Thanks!
Xeon.
Listing the Files in a Directory
http://msdn.microsoft.com/en-us/library/aa365200(VS.85).aspx
-
August 26th, 2008, 08:44 PM
#5
Re: Need a simple program!
Thanks a lot, guys! Actually, this program is for a friend of mine who wants to list the file names of all the videos in his folder (he has hundreds of videos), and he needs to send the list to me.
The steps given by gjs is very good, but even I myself is stuck at that cos' I've never really touched MS-DOS in my life, same as my friend.
So, if anyone could generate a small simple program doing the above and attach it to this thread, I would be grateful! (specs: looping through the folder, getting all the file names and putting them in text box for easy copying)
I wanted to copy ashukasama and Bitshifter's code to create my own program yesterday, but I found my VC++ 6.0 software was missing since 2 years ago!
And this is not school homework! View my past posts and you'll see I'm some sort of half-boiled shareware programmer at one time.
"Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria
"I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria
-
August 26th, 2008, 08:52 PM
#6
Re: Need a simple program!
Just do what gjs368 suggested. It'll take 30 seconds. No program needed.
-
August 26th, 2008, 09:34 PM
#7
Re: Need a simple program!
Xeon,
It's obvious that you can type...
And as mentioned above, this is really NOT that complicated. The hardest part of it is the same no matter.. You have to navigate to the folder that you want to list. If you want it simpler than typing the path, well then, just open up Windows Explorer and navigate to the folder that you want a listing from with your mouse, copy the FULL directory listing from the address bar to the Clipboard, and paste it into a command window for step 2 of my original post (at the cursor, type in the two letters cd <change directory> then a space, and then right click in the window to paste the address you copied in from the Explorer address bar).
-
August 26th, 2008, 09:41 PM
#8
Re: Need a simple program!
Thanks a lot, guys.
My problem is that when I open up the DOS window, the directory path is at:
C:\Documents and Settings\Xeon >
The path to the folder containing the vids is "C:\Documents and Settings\ops-Xeon\Desktop\VidsFolder"
So, I tried to type the following:
C:\Documents and Settings\Xeon > cd C:\Documents and Settings\ops-Xeon\Desktop\VidsFolder
But it gives an error saying "paramete format not correct".
I've also tried putting quotes around my paths but it still doesn't work.
Thanks!
Xeon
"Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria
"I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria
-
August 26th, 2008, 09:42 PM
#9
Re: Need a simple program!
Originally Posted by Xeon
Thanks a lot, guys! Actually, this program is for a friend of mine who wants to list the file names of all the videos in his folder (he has hundreds of videos), and he needs to send the list to me.
The steps given by gjs is very good, but even I myself is stuck at that cos' I've never really touched MS-DOS in my life, same as my friend.
The command-line is not MS-DOS. MS-DOS is the old 16-bit operating system that was popular during the 1980's and early 1990's.
But in all seriousness, any self-respecting Windows programmer should know how to use the command-line. There really is no excuse for a programmer not knowing simple commands such as "dir", "copy", "cd", etc.
Regards,
Paul McKenzie
-
August 26th, 2008, 09:45 PM
#10
Re: Need a simple program!
As gjs368 said, put this code into into a file then give it a .bat extension.
When you double click on the batch file it will spit the results into a text file.
This searches the current directory for all file types and sub-directories.
It doesn't get any easier than this...
Code:
@echo off
dir > results.txt
pause
-
August 26th, 2008, 09:47 PM
#11
Re: Need a simple program!
Bitshifter, using GetCurrentDirectoryA can come back to bite you....
Originally Posted by bitshifter420
Here's how you find files in the directory that this .exe resides in:
Code:
#include <windows.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv)
{
CHAR szDir[MAX_PATH];
GetCurrentDirectoryA(sizeof(szDir), szDir);
printf("Path: %s\n\n", szDir);
strcat(szDir, "\\*");
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(szDir, &ffd);
do
{
if(!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
LARGE_INTEGER filesize;
filesize.LowPart = ffd.nFileSizeLow;
filesize.HighPart = ffd.nFileSizeHigh;
printf("Name: %s\t\tSize: %ld\n", ffd.cFileName, filesize.QuadPart);
}
}
while(FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
puts("\nOperation Complete.");
getchar();
return 0;
}
Note what the function returns:
GetCurrentDirectoryA( )
This function returns the current working directory into a string
The current working directory may not be the one your app launched from. Here is a VC++ 6.0 function that should ALWAYS get you the directory the application resides in:
Code:
void GetAppDirectory(CString& szDirectory)
{
TCHAR szPath[(MAX_PATH + 1)];
TCHAR *szTemp = NULL;
GetModuleFileName(NULL, szPath, (sizeof(TCHAR) * MAX_PATH));
szTemp = strrchr(szPath, _TCHAR('\\'));
if (szTemp) *szTemp = NULL;
szDirectory.Format(_T("%s"), szPath);
}
-
August 26th, 2008, 09:50 PM
#12
Re: Need a simple program!
Originally Posted by Xeon
Thanks a lot, guys.
My problem is that when I open up the DOS window, the directory path is at:
C:\Documents and Settings\Xeon >
The path to the folder containing the vids is "C:\Documents and Settings\ops-Xeon\Desktop\VidsFolder"
So, I tried to type the following:
C:\Documents and Settings\Xeon > cd C:\Documents and Settings\ops-Xeon\Desktop\VidsFolder
But it gives an error saying "paramete format not correct".
I've also tried putting quotes around my paths but it still doesn't work.
We can't help you directly, since we don't have access to your computer. We don't know if that directory really exists. We don't know if you're really typing in that command-line. We don't know anything -- this needs to be diagnosed by you by first knowing how to use the cd command properly.
Can you change to the root directory?
If you can, then go up one folder at a time:
Code:
cd Documents and Settings
If this takes you to the directory, then go up another level. If it doesn't then your directory is not named "Documents and Settings", or it is hidden and you can't get access to it, or some other error we can't diagnose from our end.
Regards,
Paul McKenzie
-
August 26th, 2008, 09:54 PM
#13
Re: Need a simple program!
Originally Posted by gjs368
Bitshifter, using GetCurrentDirectoryA can come back to bite you....
Yes, that's not my normal practice, i was trying to keep the code small.
I should have supplied a function that strips the name off of argv[0].
Anyway, thanks for the constructive criticism.
-
August 26th, 2008, 09:55 PM
#14
Re: Need a simple program!
Originally Posted by Xeon
Thanks a lot, guys.
My problem is that when I open up the DOS window, the directory path is at:
C:\Documents and Settings\Xeon >
The path to the folder containing the vids is "C:\Documents and Settings\ops-Xeon\Desktop\VidsFolder"
So, I tried to type the following:
C:\Documents and Settings\Xeon > cd C:\Documents and Settings\ops-Xeon\Desktop\VidsFolder
But it gives an error saying "paramete format not correct".
I've also tried putting quotes around my paths but it still doesn't work.
Thanks!
Xeon
I have mislead you a bit, sorry... The command line does not know how to deal with the spaces (Just like MS to go half-way by letting you use spaces and then have grief over trying to get there....) unless you enclose the path in quotes... Try this:
cd "C:\Documents and Settings\ops-Xeon\Desktop\VidsFolder"
-
August 26th, 2008, 10:19 PM
#15
Re: Need a simple program!
Thanks guys!
But my main problem is with the "change directory", as follows (posted above previously):
When I open up the DOS window, the directory path is at:
C:\Documents and Settings\Xeon >
The path to the folder containing the vids is "C:\Documents and Settings\ops-Xeon\Desktop\VidsFolder"
So, I tried to type the following:
C:\Documents and Settings\Xeon > cd C:\Documents and Settings\ops-Xeon\Desktop\VidsFolder
But it gives an error saying "paramete format not correct".
I've also tried putting quotes around my paths but it still doesn't work.
I'm sure if I can get around this, everything would be smooth.
And yeah, it's not surprising for noob programmers not to know how to use these command-line stuff if all they ever did was MFC visual stuff all done in Windows 98 / XP interface.
"Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria
"I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|