how can I do this ?

  • Thread starter Thread starter Petri
  • Start date Start date
P

Petri

Hi,
I have an archive of twenty folders each with 10 files. The files in each
folder are named as 01,02...09,10. I would like to put all the files in the
archive into one folder. I need help me with a batch script or other advice
how to do this please.

Thanks very much.
 
Petri said:
Hi,
I have an archive of twenty folders each with 10 files. The files in each
folder are named as 01,02...09,10. I would like to put all the files in
the archive into one folder. I need help me with a batch script or other
advice how to do this please.

Thanks very much.

If your file names are unique then you can apply the
commands below. Note that it will probably take
more time to type in the commands than it will to do
it manually twenty times from within Explorer . . .

cd /d "c:\documents and settings\Petri\My Documents"
md Archive
for /d %a in (*.*) do move "%a\*.*" Archive

Double the % signs when running this in a batch file.

P.S. Have a look at your Subject line and how to
make it a bit more meaningful.
 
I'm not sure your suggestion will do what I need Pegasus.
I'm not learned enough to adapt it.

I have a folder "main". This has 20 subfolders which are named
as "01","02"..."10".

Each subfolder has 10 files which are named "01","02",..."10".

I want to put the contents of each subfolder into a new folder "new", but it
will be necessary to rename/renumber the files in the process.

Hope there is a way to do this.
 
Petri,

Why do you need a batch file to do this?

Why do you always ask for batch files in a XP group & not one that is for
batch files?

Why not ask for VBS files in the scripting newsgroup?
 
Good to see that you have further thought about this process
and realised that a rename step will be involved. Try the
batch file below:

@echo off
set Source=c:\documents and settings\Petri\My Documents
set Target=c:\documents and settings\Petri\My Documents\Archive
md "%Target%"

cd /d "%Source%"
for /d %%a in (*.*) do call :Sub %%a
cd /d "%Source%
del \dir.txt
goto :eof

:Sub
cd "%Source%\%1"
dir /b > \dir.txt
for /F %%a in (\dir.txt) do ren %%a %1%%a
move *.* "%Target%"

Each file name will be preceded by the folder name in
which it is located. Set Source and Target in lines 2
and 3 to reflect your own environment.

Doing it manually will probably be faster for a one-off
exercise.
 
thanks! you're very kind helping out.

Pegasus said:
Good to see that you have further thought about this process
and realised that a rename step will be involved. Try the
batch file below:

@echo off
set Source=c:\documents and settings\Petri\My Documents
set Target=c:\documents and settings\Petri\My Documents\Archive
md "%Target%"

cd /d "%Source%"
for /d %%a in (*.*) do call :Sub %%a
cd /d "%Source%
del \dir.txt
goto :eof

:Sub
cd "%Source%\%1"
dir /b > \dir.txt
for /F %%a in (\dir.txt) do ren %%a %1%%a
move *.* "%Target%"

Each file name will be preceded by the folder name in
which it is located. Set Source and Target in lines 2
and 3 to reflect your own environment.

Doing it manually will probably be faster for a one-off
exercise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top