How to make infinite loop if I want to change filename every time?

#include <direct.h>
int main()
for(;;) {
mkdir("c:/myfolder");
return 0;
}
I want to make c:/myfolder then c:/myfolder1, c:/myfolder2 and etc...
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <direct.h>
#include <stdio.h>
#include <cstring>

int main()
 {
     int i = 0;
     char folder[100];
     for( ;; ) 
     {
         sprintf(folder, "c:\\myfolder%d", i++);
         mkdir(folder);
     }
     return 0;
 }


Note : Warnings ahead. Don't try this at home.
Does that help you? :)
Wow that's cool. But if I want to copy file like .cpp like that?
Last edited on
> But if I want to copy file like .cpp like that?
What do you mean?
like untitled.cpp copy to c:\\untitled0.cpp, c:\\untitled1.cpp and etc...
P.S. look at pm.
Then you know the function mkdir() which is used to make a new folder, do you know the function that copies a file?
copy_file("C:\\Untitled.cpp","D:\\Untitled.cpp"); but what to do with "folder" and what to write instead?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
#include <fstream>
#include <direct.h>
#include <stdio.h>
#include <cstring>

void copyF(const char *from, const char * to)
{
    std:: ifstream src(from, std::ios::binary);
    std:: ofstream  dst(to, std::ios::binary);
    dst << src.rdbuf();
}

int main()
 {
     int i = 0;
     char file[100];
     for( ;; ) 
     {
         sprintf(file, "c:\\untitled%d.cpp", i++);
         copyF("c:\\untitled.cpp", file);
     }
     return 0;
 }


Note : Warnings ahead. Don't try this at home.
Or :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <direct.h>
#include <stdio.h>
#include <cstring>

int main()
 {
     int i = 0;
     char file[100];
     for( ;; ) 
     {
         sprintf(file, "c:\\untitled%d.cpp", i++);
         copy_file(file, "c:\\untitled.cpp");
     }
     return 0;
 }


Note : Warnings ahead. Don't try this at home.
Last edited on
Does that help? :)
Yes, it does, thanx, maybe can you give me example of copying untitled0.cpp file once but if it exists create untitled1.cpp or somehow?
Last edited on
> Maybe can you give me example of copying untitled.cpp file once but if it does not exist create untitled.cpp or somehow?

Is it what you meant?
Last edited on
I wrote:
> maybe can you give me example of copying untitled0.cpp file once but if it exists create untitled1.cpp or somehow?
Last edited on
> Maybe can you give me example of copying untitled0.cpp file once but if it exists create untitled1.cpp or somehow?
Can you clarify what you mean?
open .exe (cik cik) which copies file from d:\\untitled.cpp to c:\\untitled0.cpp (if c:\\untitled0.cpp does not exits). But c:\\untitled0.cpp exists, copy_file(d:\\untitled.cpp, c:\\untitled1.cpp, 0).
Last edited on
If it's difficult never mind. It's not important for me, I'm just curious. You helped me a lot generally.
Last edited on
Topic archived. No new replies allowed.