Solved batch file request

saphire199

New member
Local time
7:24 PM
Messages
6
Hi, don't know if anyone has any ideas on this, but here goes - I have a removeable drive with over 100,000 karaoke zip files. Currently, a typical path is "T:\karaoke\soundchoice\100x". That folder may contain 1000's of zip files, and may even be broken down into more folders. I want all the zip files to be on the path "T:\example.zip" so that I can set up my own filing system and also edit files where needed. This involves moving the zip files out of their current folder (ex - "T:\karaoke\soundchoice\100x") and putting them directly onto the "T:" path, then deleting the now empty folders.

I would like a batch file to do the above. Thank you.
 

My Computer

Computer Manufacturer/Model Number
Dell XPS 420
OS
Windows 7 Ultimate X64
CPU
Quad Core Q6600
Memory
8G Corsair
Graphics Card(s)
Nvidia 8800GT
Sound Card
Soundblaster X-Fi Fatality Pro
Screen Resolution
1680x1050
Hard Drives
raid 0, 2-1tb wd black caviar
Internet Speed
6 mb
First, are you sure there are no naming conflicts? If any of them have the same name then they can't both be in the same folder.

If you are sure that is okay, I believe xcopy from a Command Prompt can do what you want.

xcopy t:\*.zip t:\example.zip\ /s/r/i/k/e

Enter xcopy /? from a Command Prompt to see what the options mean and what others are available.

I've not tested this but I believe it will work. Give it a try. To test, add /p so it will prompt you before creating each destination file.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Lenovo IdeaCenter 450
OS
Windows 10 Pro X64
CPU
Intel Quad Core i7-4770 @ 3.4Ghz
Memory
16.0GB PC3-12800 DDR3 SDRAM 1600 MHz
Graphics Card(s)
Intel Integrated HD Graphics
Sound Card
Realtek HD Audio
Monitor(s) Displays
HP 22" LCD
Screen Resolution
1680 x 1050
Hard Drives
250GB Samsung EVO SATA-3 SSD
2TB Seagate ST2000DM001 SATA-2
1.5TB Seagate ST3150041AS SATA
Keyboard
Dell USB
Mouse
Lenovo USB
Internet Speed
Cable via Road Runner 3MB Upload, 30MB Download
Antivirus
Windows Defender, MBAM Pro, MBAE
Browser
Seamonkey
Other Info
UEFI/GPT
PLDS DVD-RW DH16AERSH
Thanks, this did work. I had to change directory because copying to same folder gave me a "cannot cyclic copy" error, but at least I got all the files out and could then copy just the zips back to the original directory. It is too bad that the MOVE command is not as versatile as xcopy, I could have used that. Again, thanks.
 

My Computer

Computer Manufacturer/Model Number
Dell XPS 420
OS
Windows 7 Ultimate X64
CPU
Quad Core Q6600
Memory
8G Corsair
Graphics Card(s)
Nvidia 8800GT
Sound Card
Soundblaster X-Fi Fatality Pro
Screen Resolution
1680x1050
Hard Drives
raid 0, 2-1tb wd black caviar
Internet Speed
6 mb
ok, I'm back - copy finished. The cmd utility copied all the zip files that I already had under T:\, but it copied all the directories and subs (which I now see per the switches, this is what I was asking it to do) I need the directories and subs to NOT be copied, just the zip files. Any further ideas?
 

My Computer

Computer Manufacturer/Model Number
Dell XPS 420
OS
Windows 7 Ultimate X64
CPU
Quad Core Q6600
Memory
8G Corsair
Graphics Card(s)
Nvidia 8800GT
Sound Card
Soundblaster X-Fi Fatality Pro
Screen Resolution
1680x1050
Hard Drives
raid 0, 2-1tb wd black caviar
Internet Speed
6 mb
I have an idea for a batch file. Playing with it now, will post in a little while.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Lenovo IdeaCenter 450
OS
Windows 10 Pro X64
CPU
Intel Quad Core i7-4770 @ 3.4Ghz
Memory
16.0GB PC3-12800 DDR3 SDRAM 1600 MHz
Graphics Card(s)
Intel Integrated HD Graphics
Sound Card
Realtek HD Audio
Monitor(s) Displays
HP 22" LCD
Screen Resolution
1680 x 1050
Hard Drives
250GB Samsung EVO SATA-3 SSD
2TB Seagate ST2000DM001 SATA-2
1.5TB Seagate ST3150041AS SATA
Keyboard
Dell USB
Mouse
Lenovo USB
Internet Speed
Cable via Road Runner 3MB Upload, 30MB Download
Antivirus
Windows Defender, MBAM Pro, MBAE
Browser
Seamonkey
Other Info
UEFI/GPT
PLDS DVD-RW DH16AERSH
Okay, here is what I've come up with. I tested it and it works for me.
Code:
@echo off
rem %1 - root to start copying from
rem %2 - target to copy files to
rem
rem
rem Uses dir /b /s parm1 > copydown.txt to create list of files to be copied
rem Reads the file one record at a time and copies each file listed to Pam2

if .%1 equ . goto :help
if .%2 equ . goto :help

rem Get list of files to be copied. /b tosses all header info
dir /b /s %1% > copydown.txt

for /f "tokens=*" %%a in (copydown.txt) do (
 echo copy "%%a" "%2%"
      copy "%%a" "%2%"
)

goto :done

:help
echo This command requires two parameters, P1 and P2
echo P1 is the root of the source driectory tree you want to copy files (not folders) from.
echo P2 is the target you want the files copied to.
echo .
echo copydown p1 p2
echo .
echo Example:   copydown d:\temp\*.* d:\tmp2\
echo .
echo Note the trailing slash at the end of P2, it's required.
echo P1 and P2 can not point to the same directory.
echo .
echo This will copy all files in d:\temp and all it's subdirectories to d:\tmp2
echo Sub-directories are disacrded, only the files are copied.

:done
Copy the above and paste it into copydown.bat.
From a Command Prompt, enter copydown with no parameters to see the very brief help.

I tried it exactly as shown. In d:\temp I have 41 directories and a total of 207 files.
d:\tmp2 is empty.
After running the batch file, d:\tmp2 has 207 files and no directories.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Lenovo IdeaCenter 450
OS
Windows 10 Pro X64
CPU
Intel Quad Core i7-4770 @ 3.4Ghz
Memory
16.0GB PC3-12800 DDR3 SDRAM 1600 MHz
Graphics Card(s)
Intel Integrated HD Graphics
Sound Card
Realtek HD Audio
Monitor(s) Displays
HP 22" LCD
Screen Resolution
1680 x 1050
Hard Drives
250GB Samsung EVO SATA-3 SSD
2TB Seagate ST2000DM001 SATA-2
1.5TB Seagate ST3150041AS SATA
Keyboard
Dell USB
Mouse
Lenovo USB
Internet Speed
Cable via Road Runner 3MB Upload, 30MB Download
Antivirus
Windows Defender, MBAM Pro, MBAE
Browser
Seamonkey
Other Info
UEFI/GPT
PLDS DVD-RW DH16AERSH
Thank you very much, this worked perfectly. I appreciate that someone with a lot of tech know-how spent the time to figure this out for someone else.

Since I am also trying to learn, would you mind explaining the programming? I get the "dir" cmd, to bring up the files and get rid of the headers and send to copydown.txt. Could you break down the "for" cmd remarks? Especially the first line, I get that after that you are copying what came up to the screen and the destination. I also read "for" help, I just would like it explained a bit more in layman terms so I can understand more of what it is doing. Again, thank you.
 

My Computer

Computer Manufacturer/Model Number
Dell XPS 420
OS
Windows 7 Ultimate X64
CPU
Quad Core Q6600
Memory
8G Corsair
Graphics Card(s)
Nvidia 8800GT
Sound Card
Soundblaster X-Fi Fatality Pro
Screen Resolution
1680x1050
Hard Drives
raid 0, 2-1tb wd black caviar
Internet Speed
6 mb
Read this article, see if it helps. Batch files - The FOR command: Windows NT 4/Windows 2000 Syntax

Basically though, tokens=* means the entire line of data is passed to the body of the FOR loop.
tokens=1,2* would mean the first delimited word frm the line would be the first token, the second the second and the rest the third.

At least I think that's how it works.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Lenovo IdeaCenter 450
OS
Windows 10 Pro X64
CPU
Intel Quad Core i7-4770 @ 3.4Ghz
Memory
16.0GB PC3-12800 DDR3 SDRAM 1600 MHz
Graphics Card(s)
Intel Integrated HD Graphics
Sound Card
Realtek HD Audio
Monitor(s) Displays
HP 22" LCD
Screen Resolution
1680 x 1050
Hard Drives
250GB Samsung EVO SATA-3 SSD
2TB Seagate ST2000DM001 SATA-2
1.5TB Seagate ST3150041AS SATA
Keyboard
Dell USB
Mouse
Lenovo USB
Internet Speed
Cable via Road Runner 3MB Upload, 30MB Download
Antivirus
Windows Defender, MBAM Pro, MBAE
Browser
Seamonkey
Other Info
UEFI/GPT
PLDS DVD-RW DH16AERSH
Just wanted to say a final thank you, this helped me solve the problem and understand how to solve similar problems in the future on my own.
 

My Computer

Computer Manufacturer/Model Number
Dell XPS 420
OS
Windows 7 Ultimate X64
CPU
Quad Core Q6600
Memory
8G Corsair
Graphics Card(s)
Nvidia 8800GT
Sound Card
Soundblaster X-Fi Fatality Pro
Screen Resolution
1680x1050
Hard Drives
raid 0, 2-1tb wd black caviar
Internet Speed
6 mb
You're welcome. AS I said, this is fun to me. Glad you problem is solved.

Peace
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Lenovo IdeaCenter 450
OS
Windows 10 Pro X64
CPU
Intel Quad Core i7-4770 @ 3.4Ghz
Memory
16.0GB PC3-12800 DDR3 SDRAM 1600 MHz
Graphics Card(s)
Intel Integrated HD Graphics
Sound Card
Realtek HD Audio
Monitor(s) Displays
HP 22" LCD
Screen Resolution
1680 x 1050
Hard Drives
250GB Samsung EVO SATA-3 SSD
2TB Seagate ST2000DM001 SATA-2
1.5TB Seagate ST3150041AS SATA
Keyboard
Dell USB
Mouse
Lenovo USB
Internet Speed
Cable via Road Runner 3MB Upload, 30MB Download
Antivirus
Windows Defender, MBAM Pro, MBAE
Browser
Seamonkey
Other Info
UEFI/GPT
PLDS DVD-RW DH16AERSH
Back
Top