Originally posted by namejm at 2006-8-14 20:04:
If you want to use xcopy, it won't be that simple, because the OP wants to copy the three files a1.txt, a2.txt, and a3.txt from each subdirectory, and also requires that the location of the bbb directory can be specified arbitrarily. ...
I tried it according to your method, boss, and it wasn't ideal. While it copied the needed files into the BBB directory, it also moved the other grandchild directories inside AAA (subdirectories of subdirectories—don't know if that's the right term?) into the BBB directory as well.
After tinkering with it all day, I finally made one myself. It's not bad and basically meets my requirements. I'll post it here, boss—please help analyze it and see whether it can be made more concise. Mainly I'm using it to make a WindowsXP OEM 20-in-1 disc. Before, manually extracting and copying files was really annoying, and it was easy to make mistakes.
This thing I cobbled together myself:
@Echo Off
Set TT=WindowsXP OEM File Extraction and Copy Tool
COLOR 1F
TITLE %TT%
:start
CLS
Echo.
Echo ╭══════════════════╮
Echo ║ ║
Echo ╭═══┤ WindowsXP OEM File Extraction and Copy Tool ├═══╮
Echo ║ ║ ║ ║
Echo ║ ╰══════════════════╯ ║
Echo ║ ║
Echo ║ Do you want to extract OEM files from a CD or hard disk? ║
Echo ║ Or do you want to copy existing OEM files to the hard disk? ║
Echo ║ ║
Echo ║ Extract OEM files from a CD or hard disk ║
Echo ║ Copy existing OEM files to the hard disk ║
Echo ║ Extract OEM icons from a CD or hard disk ║
Echo ║ Copy existing OEM icons to the hard disk ║
Echo ║ Exit ║
Echo ║ ║
Echo ╟──────────────────────────╢
Echo ║ Note: 1. Enter the absolute path of the CD or hard disk file directory yourself according to the prompt.║
Echo ║ 2. Spaces are not allowed in the file path. ║
Echo ╟══════════════════════════╢
Echo ║ Copyright: jtyuer For exchange and study by forum friends, reprints not prohibited ║
Echo ╰──────────────────────────╯
Echo.
Set Choice=
Set /P Choice= Please choose the operation to perform (1/2/3/4/Q), then press Enter:
If Not '%Choice%'=='' SET Choice=%Choice:~0,1%
If /I '%Choice%'=='1' GOTO funa
If /I '%Choice%'=='2' GOTO funa
If /I '%Choice%'=='3' GOTO funa
If /I '%Choice%'=='4' GOTO funa
If /I '%Choice%'=='Q' EXIT
Goto start
:funa
If /I '%Choice%'=='1' (
TITLE %TT% - Extract OEM files from CD or hard disk
)
If /I '%Choice%'=='2' (
TITLE %TT% - Copy existing OEM files to hard disk
Goto funb
)
If /I '%Choice%'=='3' (
TITLE %TT% - Copy existing OEM icons to hard disk
Goto func
)
If /I '%Choice%'=='4' (
TITLE %TT% - Copy existing OEM icons to hard disk
Goto fund
)
If "%Err%"=="" (
CLS
)
:funa1
cls
Echo Please enter the directory name where the OEM files are located, such as c:\1234
Echo.
Echo Do not include the i386 subdirectory path when entering the path
echo.
Set input=
Set /P input= Enter path:
If "%input%"=="" Goto funa
If Not Exist %input% (
Set Err=1
Echo.
CLS
Echo The OEM file directory path you entered is incorrect, please enter it again
Echo.
Goto :funa1
)
::funa2
cls
Echo Please enter the directory name to save the OEM files, such as d:\1234
echo.
Set output=
Set /P output= Enter path:
If "%input%"=="" Goto funa1
If Not Exist %output% (
Set Err=1
Echo.
CLS
Echo The directory %output% for saving OEM files does not exist; %output% will be created automatically
Echo.
Echo.
Echo.
@md %output%
)
:Copy
@Echo dpcdll.dl_>%temp%\oem.txt
@Echo oembios.bi_>>%temp%\oem.txt
@Echo oembios.ca_>>%temp%\oem.txt
@Echo oembios.da_>>%temp%\oem.txt
@Echo oembios.si_>>%temp%\oem.txt
@Echo pidgen.dll>>%temp%\oem.txt
@Echo setupp.ini>>%temp%\oem.txt
@Echo winnt.sif>>%temp%\oem.txt
for /f %%a in ('dir /ad /b %input%') do md %output%\%%a\i386 & FOR /f %%b in (%temp%\oem.txt) do copy /y %input%\%%a\i386\%%b %output%\%%a\i386\
Goto Exit
:funb
cls
Echo Please enter the directory name where the OEM files are located, such as c:\1234
Echo.
Echo Do not include the i386 subdirectory path when entering the path
echo.
Set input=
Set /P input= Enter path:
If "%input%"=="" Goto funb
If Not Exist %input% (
Set Err=1
Echo.
CLS
Echo The OEM file directory path you entered is incorrect, please enter it again
Echo.
Goto funb
)
:funb1
cls
Echo Please enter the directory name to copy the OEM files to, such as d:\1234
echo.
Set output=
Set /P output= Enter path:
If "%input%"=="" Goto funb1
If Not Exist %output% (
Set Err=1
Echo.
CLS
Echo The directory %output% for saving OEM files does not exist; %output% will be created automatically
Echo.
Echo.
@md %output%
)
:Copy
For /f %%m In ('dir /ad /b %input%') do md %output%\%%m\i386 & Copy /y %input%\%%m\i386\*.* %output%\%%m\i386\
Goto Exit
:func
cls
Echo Please enter the directory name where the OEM icons are located, such as c:\1234
Echo.
Set input=
Set /P input= Enter path:
If "%input%"=="" Goto func
If Not Exist %input% (
Set Err=1
Echo.
CLS
Echo The OEM icon directory path you entered is incorrect, please enter it again
Echo.
Goto func
)
:func1
cls
Echo Please enter the directory name to copy the OEM icons to, such as d:\1234
echo.
Set output=
Set /P output= Enter path:
If "%input%"=="" Goto funb1
If Not Exist %output% (
Set Err=1
Echo.
CLS
Echo The directory %output% for saving OEM icons does not exist; %output% will be created automatically
Echo.
Echo.
@md %output%
)
:Copy
If Exist %temp%\ml.txt Del %temp%\ml.txt
If Exist %temp%\oem.txt Del %temp%\oem.txt
@Echo oeminfo.ini>%temp%\oem.txt
@Echo oemlogo.bmp>>%temp%\oem.txt
for /f %%a in ('dir /ad /b %input%') do md %output%\%%a\$OEM$\$$\SYSTEM32 & FOR /f %%b in (%temp%\oem.txt) do copy /y %input%\%%a\$OEM$\$$\SYSTEM32\%%b %output%\%%a\$OEM$\$$\SYSTEM32\
Goto Exit
:fund
cls
Echo Please enter the directory name where the OEM icons are located, such as c:\1234
Echo.
Set input=
Set /P input= Enter path:
If "%input%"=="" Goto fund
If Not Exist %input% (
Set Err=1
Echo.
CLS
Echo The directory path where the OEM icons are located is incorrect, please enter it again
Echo.
Goto fund
)
:fund1
cls
Echo Please enter the directory name to copy the OEM icons to, such as d:\1234
echo.
Set output=
Set /P output= Enter path:
If "%input%"=="" Goto fund1
If Not Exist %output% (
Set Err=1
Echo.
CLS
Echo The directory %output% for saving OEM files does not exist; %output% will be created automatically
Echo.
@md %output%
)
:Copy
For /f %%m In ('dir /ad /b %input%') do md %output%\%%m\$OEM$\$$\SYSTEM32 & Copy /y %input%\%%m\$OEM$\$$\SYSTEM32\*.* %output%\%%m\$OEM$\$$\SYSTEM32\
Goto Exit
:Exit
CLS
Echo.
Echo ╭══════════════════╮
Echo ║ ║
Echo ╭═══┤ WindowsXP OEM File Extraction and Copy Tool ├═══╮
Echo ║ ║ ║ ║
Echo ║ ╰══════════════════╯ ║
Echo ║ ║
Echo ║ The operation you needed has been completed. Please check. . . ║
Echo ║ Thank you for using it! ║
Echo ║ Are you going to continue copying files? ║
Echo ║ ║
Echo ║ ║
Echo ║ Continue copying files ║
Echo ║ ║
Echo ║ Exit ║
Echo ║ ║
Echo ╟──────────────────────────╢
Echo ║ Note: 1. Enter the absolute path of the CD or hard disk file directory yourself according to the prompt.║
Echo ║ 2. Spaces are not allowed in the file path. ║
Echo ╟══════════════════════════╢
Echo ║ Copyright: jtyuer For exchange and study by forum friends, reprints not prohibited ║
Echo ╰──────────────────────────╯
Echo.
Set Choice=
Set /P Choice= Please choose the operation to perform (y/n), then press Enter:
If Not '%Choice%'=='' SET Choice=%Choice:~0,1%
If /I '%Choice%'=='y' GOTO start
If /I '%Choice%'=='n' GOTO end
Goto Exit
:End