-
Hi,
can anybody suggest either an app/software for Windows, a script or a way to duplicate a folder with its entire content a large number of times (like 10,000 or more)?
I tried few scripts from various forums but none of them seem to be working. :o
Thank you :)
-
What operating system are you using?
-
Windows 10 (I updated it now in the OP)
Thank you Zero999
-
Windows 10 has WSL, therefore a bash script should work. Or you can use Powershell if that's what you prefer.
-
Make an archive of the folder you want duplicated ... can be an archive without compression like TAR for example, or ZIP / 7zip with no compression or ultrafast compression
Generate the numbers you want using whatever website or script you can find, for example try : https://www.reformattext.com/sequential-number-generator.htm (https://www.reformattext.com/sequential-number-generator.htm)
Tell the website or script to print one number per line, with some sequence of characters before and after each number.
(https://www.eevblog.com/forum/projects/duplicating-a-folder-with-its-content-n-number-of-times/?action=dlattach;attach=1245558;image)
You get something like this :
abc00001xyz
abc00002xyz
abc00003xyz
Basically, you want to form the command line to unpack the archive on each line, by replacing text before the number with something, and the text after number with something.
For example, assuming the archive is C:\temp\temp.tar and you want it extracted in C:\temp\00001\ , C:\temp\00002 and so on, you want each line to look like this :
7z.exe x -o"C:\temp\00001" "c:\temp\temp.tar"
x means extract, keeping the folder structure inside the archive intact
-o means specify output folder
use "" if there's spaces in the file or folder paths.
So you paste those numbers in notepad or any other text editor, and do two search and replace commands
Search for : abc
Replace with : 7z.exe x -o"C:\temp\
Search for : xyz
Replace with : " "c:\temp\temp.tar"
and your text file becomes :
7z.exe x -o"C:\temp\00001" "c:\temp\temp.tar"
7z.exe x -o"C:\temp\00002" "c:\temp\temp.tar"
7z.exe x -o"C:\temp\00003" "c:\temp\temp.tar"
Now select the file with a .BAT extension in the same folder with 7z.exe from 7zip (you can copy it from program files somewhere else, like a temporary folder) and run the batch file and the archive will be unpacked as many times as you have lines in the batch file.
(In notepad, you do File > Save as ... select any file type, then type your file name and add .bat at the end, and the file will be saved as a batch file .. otherwise it's saved as a .TXT file)
Or use something else under linux or mac if that's what you're using.
Test it with 5-10 numbers and if all looks good to you, do it with 10k or whatever.
-
That's gratuitously dumb. Even in a CMD batch script you can increment a variable with set /a. See https://ss64.com/nt/set.html#expressions
-
It may be dumb, but it's super easy.
Doing a search and replace twice is super easy and idiot proof.
I've worked with computers since the Turbo Pascal days and 486 days and I never bothered to learn batch file programming, and even if I learn it now, using it so little I'll soon forget it..
For me it's much more intuitive to write a few lines in a language like php and run the php script from command line, but if the job can be done with two search and replace commands in notepad and it works .... :
$handle = fopen("c:/temp/batch.bat","w"); // open batch file for writing
for ($i=1;$i<=10000;$i++) {
$nr = str_pad($i,5,"0",STR_PAD_LEFT); // put up to 5 "0"characters in front of our number, converted into string
fwrite($handle, "7z.exe x -o\"C:\\temp\\$nr\" \"c:\\temp\\temp.tar\"\r\n"); // " and \ characters have to be escaped by placing \ in front
}
fclose($handle);
-
Mmm, just wondering why you want 10,000 of the same thing.
Is this for some distribution that will be further customized?
-
@mariush,
Maybe so, but CMD scripting is the lowest common denominator that you can be certain will be available on any Windows PC. There are a few gotchas if you go back before Win XP but otherwise its pretty much identical from then to now.
@all,
Here's a batch script that counts:
@echo off
set /a limit=1000
set /a loopvar=0
:loop
echo Do something with %loopvar%
rem your code here
set /a loopvar+=1
if %loopvar% leq %limit% goto loop
rem cleanup
set limit=
set loopvar=
-
Am I missing something?
Are leading zeroes even possible in a straight .bat file?
-
It would be trivial to do this with a Python script.
-
I once did that. Not 10,000 copies, but until the hard drive was full.
Why? I was leaving a job under bad circumstances. I had installed several programs on my office computer and I did not want to leave them as that employer did not have any rights to use them: I did have that right. I left all the data files that I had created with them, but erased the programs. But it was very easy to un-do that so I wanted to over write the entire hard drive.
I used a batch file employing DOS commands to copy a bunch of files until the drive was full. It only took a minute to write and set in motion.
I have not written or used a batch file (.bat) in years, but it appears that you still can via the command prompt window which is still in Windows 10. Here is how a loop is written:
http://www.trytoprogram.com/batch-file-for-loop/ (http://www.trytoprogram.com/batch-file-for-loop/)
You can easily use values of 1 and 10000 in that. The rest is a simple command to copy that directory.
Mmm, just wondering why you want 10,000 of the same thing.
Is this for some distribution that will be further customized?
-
Am I missing something?
Are leading zeroes even possible in a straight .bat file?
Yes, and it isn't even that tricky to do. Conceptually, you need to concatenate a string of sufficient leading zeros with the number then slice out the the desired number of digits from the end of the resulting string. In practice, this code:
set zplv=0000%loopvar%
set zplv=%zplv:~-5%
echo Do something with zero padded no. %zplv%
will do it. Simply add it as 'payload' to the loop of the batch script I posted above.
@EPAIII,
Unfortunately the batch FOR command was originally only intended to repeat a single command for all or a subset of the files in a directory. There is no NEXT command. Everything else it can do has been bolted on to that original functionality, resulting in a slow and fugly mess with arcane syntax if you need to execute multiple commands. Look at this: https://ss64.com/nt/delayedexpansion.html and you'll see why I went for a simple IF and GOTO above!
Believe me, it wasn't from lack of knowledge of FOR loops, as I've been using them for stuff like this since the bad old days of DOS, when the only way to do the above was to have a FOR loop process a list for each digit, something like:
for %%a in (0 1 2 3 4 5 6 7 8 9) do for %%b in (0 1 2 3 4 5 6 7 8 9) do for %%c in (0 1 2 3 4 5 6 7 8 9) do call %0 /loopbody %%a%%b%%c
then as CALL couldn't use GOTO labels, at the top of your batch file you'd test parameter %1 and if it was /loopbody you'd jump to the loop body. If you wanted to stop before 999, you'd need to test %2 in the loop body code, and once it reached the desired limit, set a flag to skip the loop body thereafter. Fortunately the NT family command processor was available as an extra for Win9x, (Win95Cmd) so I was able to escape from raw DOS batch syntax sooner than many others.
-
I'm not sure why it needs to be so complicated :
for /L in %G in (1,1,10000) DO xcopy /E /I sourcedir destdir-%g
If using in a batch file make the %g %%g
If you are worried about the number being consistent length, start with (10000,1,20000) and number them 10000-20000.
-
Thank you a :)
-
Am I missing something?
Are leading zeroes even possible in a straight .bat file?
Yes, and it isn't even that tricky to do. Conceptually, you need to concatenate a string of sufficient leading zeros with the number then slice out the the desired number of digits from the end of the resulting string. In practice, this code:
set zplv=0000%loopvar%
set zplv=%zplv:~-5%
echo Do something with zero padded no. %zplv%
will do it. Simply add it as 'payload' to the loop of the batch script I posted above.
@EPAIII,
Unfortunately the batch FOR command was originally only intended to repeat a single command for all or a subset of the files in a directory. There is no NEXT command. Everything else it can do has been bolted on to that original functionality, resulting in a slow and fugly mess with arcane syntax if you need to execute multiple commands. Look at this: https://ss64.com/nt/delayedexpansion.html and you'll see why I went for a simple IF and GOTO above!
Believe me, it wasn't from lack of knowledge of FOR loops, as I've been using them for stuff like this since the bad old days of DOS, when the only way to do the above was to have a FOR loop process a list for each digit, something like:
for %%a in (0 1 2 3 4 5 6 7 8 9) do for %%b in (0 1 2 3 4 5 6 7 8 9) do for %%c in (0 1 2 3 4 5 6 7 8 9) do call %0 /loopbody %%a%%b%%c
then as CALL couldn't use GOTO labels, at the top of your batch file you'd test parameter %1 and if it was /loopbody you'd jump to the loop body. If you wanted to stop before 999, you'd need to test %2 in the loop body code, and once it reached the desired limit, set a flag to skip the loop body thereafter. Fortunately the NT family command processor was available as an extra for Win9x, (Win95Cmd) so I was able to escape from raw DOS batch syntax sooner than many others.
I used to use QBASIC for a lot of things, which can now be done using batch files.
-
Why dont you use the CTRL+A CTRL+C CRTL+V method ?
It doubles each time u use it, and you have 10.000 faster then you read this topic.
The problem is naming, copy of copy of copy of file.exe
-
Install the git bash shell and do something like,
ncopies=10
src_folder=files
dst_folder_prefix=more_files_
for n in $(seq 1 ncopies) ; do cp -r $src_folder ${dst_folder_prefix}${n} ; done