Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to iterate through moveing files from diretory to another, I would like to move them in groups of 4, 5 or 10. I am using the system command to do this
example:
char file[245] = "MORE | MOVE /Y
:\\dir1\\dir2\\*.gz C:\\dir1\\dir3\\" ;if(system(dir2)){
cout << "Moving files 4 at time.\n\n";
for(int cnt = 1; cnt <= 4; ++cnt){
system(file);
++cnt;
}The catch is that all my files have the same file extension .gz and the nameing convention is different by dates.
Any sugestion?
Thanks,
Deman

Hi. Have you tried something like this (I will explain after):
----------------
#include <stdio.h>
#include <dir.h>void move_four_files(void)
{
int i;
struct ffblk fblock;
char cmd[256];/* Move the first file */
if(!findfirst("C:\\dir1\\dir2\\*.gz",&fblock,NORMAL)!=0) {
printf("Not found.");
exit(-1);
}sprintf(cmd,"move %s C:\\dir1\\dir3\\",fblock.ff_name);
system(cmd);/* Move the rest */
for(i=1;i<=3;i++) {
if(findnext(&fblock)!=0) {
printf("Not found.");
exit(-1);
}
sprintf(cmd,"move %s C:\\dir1\\dir3\\",fblock.ff_name);
system(cmd);
}return;
}----------------
This should work on most any computer with a DOS compiler (maybe a Windows one too, not sure.) You may want to research the functions I demonstrated to make sure I didin't make a mistake, but I'm pretty sure that it's OK.
The source code above utilizes two important functions: findfirst(), and findnext(). The function that finds the first entry in a directory is findfirst(), which takes wildcards. The second one finds the next entry in the directory. If you make the source code above one function, you can just call it, and it will delete four items at a time.Good luck.

![]() |
TCP/IP programming - urge...
|
search for words in textf...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |