Computing.Net > Forums > Programming > Moving Files one at a time

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Moving Files one at a time

Reply to Message Icon

Name: deeman1
Date: September 6, 2004 at 03:21:35 Pacific
OS: Win2k/XP
CPU/Ram: P4 3.06 / 1.00 Gig
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: karluk87
Date: September 15, 2004 at 20:59:37 Pacific
Reply:

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.



0
Reply to Message Icon

Related Posts

See More


TCP/IP programming - urge... search for words in textf...



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Moving Files one at a time

Two windows, close one at a time www.computing.net/answers/programming/two-windows-close-one-at-a-time/4157.html

Need script to handle multiple file www.computing.net/answers/programming/need-script-to-handle-multiple-file/15315.html

perl program call www.computing.net/answers/programming/perl-program-call/5708.html