Jump to content

Need help making 100+ copies of a folder


RainDreamer

Recommended Posts

I am currently in need of a quick batch file, or something of the kind that makes copies a folder and its content then rename the folder numerically.

Basically, I need to make multiple copies of a folder with a name like, texture00, and rename it as texture01, texture02, texture03 and so on, with the output in the same directory.

 

Anyone know how to do this?I am modding some game I am playing and making copies manually for over a 100 folder is tiresome.

Edit: This is in window 10

Edited by RainDreamer
Link to comment
Share on other sites

I used to do something like this for work a while back so I was interested.

Put this in a *.bat file and run it:

mkdir C:\[YOUR CHOSEN PATH HERE]\texture01

mkdir C:\[YOUR CHOSEN PATH HERE]\texture02

mkdir C:\[YOUR CHOSEN PATH HERE]\texture03

etc...

 

Remember, google is your friend!

Link to comment
Share on other sites

21 minutes ago, p1t1o said:

I used to do something like this for work a while back so I was interested.

Put this in a *.bat file and run it:

mkdir C:\[YOUR CHOSEN PATH HERE]\texture01

mkdir C:\[YOUR CHOSEN PATH HERE]\texture02

mkdir C:\[YOUR CHOSEN PATH HERE]\texture03

etc...

 

Remember, google is your friend!

I am sure mkdir only make new, empty folders, while what I need is making multiple copies, including the content, of the first folder, and rename the newly made ones. Also I would have to name each of the folder by myself on each line, don't I? I just need something to automate that process. Googling gives me some result for making copies of files, but not entire folders.

Edited by RainDreamer
Link to comment
Share on other sites

18 minutes ago, RainDreamer said:

I am sure mkdir only make new, empty folders, while what I need is making multiple copies, including the content, of the first folder, and rename the newly made ones. Just something to automate that process. Googling gives me some result for making copies of files, but not entire folders.

Sorry mate, missed the part where you needed the contents copied too.

Typing in the numbers 01-100 takes about 60 seconds though! 

 

Ok, how about this:

Copy/paste the folders till you have 100 of them (this takes less than 100 cycles as you can copy/paste groups).

They will have names like texture00 - Copy, tecture00 - Copy 2 etc.

If "Texture - CopyXX" is not a desirable folder name, you can do a batch rename:

 

First create a *.bat file with this:

dir /b > FILENAME.txt

 

Place the .bat file in the same location as the folders. This will produce a text file in that location with a list of all files/folders.

Paste the list of files into a spreadsheet into two columns, leave one column alone and use find/replace/copy/paste to get the second column filenames to what you want them to be.

Now using spreadsheet magic (do you need to know how to do this?) create a column with the following content:

move "[PREVIOUS FOLDERNAME]" "[DESIRED FOLDERNAME]"

move "[PREVIOUS FOLDERNAME]" "[DESIRED FOLDERNAME]"

move "[PREVIOUS FOLDERNAME]" "[DESIRED FOLDERNAME]"

etc...

 

Leave out the square brackets.

INCLUDE the quotation marks.

 

EG:

move "texture" "texture00"

move "texture - copy" "texture01"

move "texture - copy (2)" "texture02"

etc.

 

Paste the commands into another .bat file, place this .bat file where the folders are and run.

 

How's that? Although you could have done it by hand by now!

 

**edit**

oops, missed a step (in bold above), fixed now!

Edited by p1t1o
Link to comment
Share on other sites

2 minutes ago, p1t1o said:

How's that? Although you could have done it by hand by now!

Yeah, probably better to just do it manually, I guess. With all that typing I would just rather renaming them one by one with less key presses.

Link to comment
Share on other sites

2 minutes ago, RainDreamer said:

Yeah, probably better to just do it manually, I guess. With all that typing I would just rather renaming them one by one with less key presses.

Yeah, stuff like his is generally only useful if you are going to do the same procedure multiple times (I think there's an XKCD about this...). Or if you need to create a really silly number of files/folders, like thousands.

Just to let you know, I missed a step, fixed above now.

Its not actually much typing though, mostly copypasta.

Edited by p1t1o
Link to comment
Share on other sites

That batch file 'aint automation, it's just typing into a file rather than the prompt :P

Been a long time since I did any scripting in Windows, if you have a method for consecutive renaming of files (and I bet it's more typing than bash brace expansion), would you not just replace the "copy file" bit with "recursive copy directory"? My vauge memories of DOS say that would be the 'xcopy' command?

Is such a simple task really so hard in Windows? surely there's an equivalent to {01..99}... I know it has for loops.

You could just install bash in cygwin. ;) This looks like a lazy method, though I have not used it.

Now I am so very glad I use a real shell.

---

Google says it would be something like:

for /l %x in (1, 1, 100) do xcopy [path]\texture00 [path]\texture%x

where (1, 1, 100) is start, step size, end.

But don't quote me on that.

 

Edited by steve_v
Stupid, stupid editor mangling my link.
Link to comment
Share on other sites

2 minutes ago, pizzaoverhead said:

for /l %i in (1,1,100) do echo d | xcopy /e MyDir MyDir%i

 

I stand corrected. I was close. :P

---

And just to be an ass, does that zero-pad the names, like 01, 02 etc.?

Edited by steve_v
Link to comment
Share on other sites

5 minutes ago, steve_v said:

That batch file 'aint automation, it's just typing into a file rather than the prompt :P

Well it replaces many hundred keypresses with a handful of copy/pastes and it is if you have to do it every week and you already have the bat files setup - although I suppose we did refer to it as "semi-automated". And if it takes less time than learning how to write shorter code.... :sticktongue:

Link to comment
Share on other sites

12 minutes ago, steve_v said:

And just to be an ass, does that zero-pad the names, like 01, 02 etc.?

Here's the extra-credit answer ;)

@echo off
setlocal ENABLEDELAYEDEXPANSION
set count=99
set dirname="texture"
echo d | xcopy /e %dirname% %dirname%00
for /l %%i in (1,1,%count%) do (
	set num=0%%i
	echo d | xcopy /e %dirname% %dirname%!num:~-2!
)

 

Edited by pizzaoverhead
Link to comment
Share on other sites

Just now, pizzaoverhead said:

Here's the extra-credit answer ;)

Thanks.
Though that is 180 (non whitespace) characters to to my 35, in bash. :P

 

43 minutes ago, p1t1o said:

Now using spreadsheet magic...

The day I need a spreadsheet to do a batch rename is the day I go looking for a better way.

Link to comment
Share on other sites

Just now, steve_v said:

The day I need a spreadsheet to do a batch rename is the day I go looking for a better way.

Not everyone knows, needs to, or wants to know, how to write code, or use weird unfamiliar programs...meanwhile I'm sitting here with thousands of identical folders whilst y'all havn't decided how many characters you can get it down to :)

 

Link to comment
Share on other sites

3 minutes ago, p1t1o said:

Not everyone knows, needs to, or wants to know, how to write code, or use weird unfamiliar programs.

If by "spreadsheet" you meant "Microsoft Excel", that's pretty much my definition of "weird unfamiliar program". Also, that spreadsheet needs a GUI... and several thousand times more CPU work than the original task, just to open it. ;)

Inefficient, most inefficient.

But eh, use what you know, I guess.

Link to comment
Share on other sites

10 minutes ago, steve_v said:

Thanks.
Though that is 180 (non whitespace) characters to to my 35, in bash. :P

 

The day I need a spreadsheet to do a batch rename is the day I go looking for a better way.

You forgot one important piece for the task at hand:

SET PATH=%PATH%;C:\cygwin64\bin

:P

 

7 minutes ago, p1t1o said:

Not everyone knows, needs to, or wants to know, how to write code, or use weird unfamiliar programs...meanwhile I'm sitting here with thousands of identical folders whilst y'all havn't decided how many characters you can get it down to :)

 

The right tool for the job is whatever one you can use to get the job done! :)

Link to comment
Share on other sites

4 hours ago, steve_v said:

One-liner in bash:


for i in {01..99}; do cp -r texture00 texture$i; done

In Windows... no idea, been too long.

Apparently Bash will be included in the next windows 10 update.

Link to comment
Share on other sites

3 hours ago, pizzaoverhead said:

Here's the extra-credit answer ;)


@echo off
setlocal ENABLEDELAYEDEXPANSION
set count=99
set dirname="texture"
echo d | xcopy /e %dirname% %dirname%00
for /l %%i in (1,1,%count%) do (
	set num=0%%i
	echo d | xcopy /e %dirname% %dirname%!num:~-2!
)

 

So, since I need to make about 138 copies, I just need to set the count to 137?

Link to comment
Share on other sites

13 minutes ago, RainDreamer said:

So, since I need to make about 138 copies, I just need to set the count to 137?

If you're smart (and are going to use this again in the future), you prompt the user for the number of copies. NEVER hardcode anything unles you're never going to use it again!

Link to comment
Share on other sites

15 minutes ago, pincushionman said:

If you're smart (and are going to use this again in the future), you prompt the user for the number of copies. NEVER hardcode anything unles you're never going to use it again!

Since I am the only user, and this is like a few lines of simple code that can easily be modified, it is all the user interface I need for future input.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...