Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: batch file request

06 Jul 2011   #1
saphire199

Windows 7 Ultimate X64
 
 
batch file request

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 System SpecsSystem Spec
.
06 Jul 2011   #2
Ztruker

Windows 10 Pro X64
 
 

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 System SpecsSystem Spec
07 Jul 2011   #3
saphire199

Windows 7 Ultimate X64
 
 

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 System SpecsSystem Spec
.

07 Jul 2011   #4
saphire199

Windows 7 Ultimate X64
 
 

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 System SpecsSystem Spec
07 Jul 2011   #5
Ztruker

Windows 10 Pro X64
 
 

I have an idea for a batch file. Playing with it now, will post in a little while.
My System SpecsSystem Spec
07 Jul 2011   #6
Ztruker

Windows 10 Pro X64
 
 

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 System SpecsSystem Spec
09 Jul 2011   #7
saphire199

Windows 7 Ultimate X64
 
 

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 System SpecsSystem Spec
10 Jul 2011   #8
Ztruker

Windows 10 Pro X64
 
 

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 System SpecsSystem Spec
11 Jul 2011   #9
saphire199

Windows 7 Ultimate X64
 
 

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 System SpecsSystem Spec
12 Jul 2011   #10
Ztruker

Windows 10 Pro X64
 
 

You're welcome. AS I said, this is fun to me. Glad you problem is solved.

Peace
My System SpecsSystem Spec
Reply

 batch file request




Thread Tools




Similar help and support threads
Thread Forum
I need a batch file to open a random file within a certain folder/path
I want a batch to select and open a random link file in a folder i have. All the links are music videos I like to listen to, and I kind of want to just have an option for 'surprise me!'. I can change the file names if I have to, and I have a basic batch file ability. I know the simple commands,...
General Discussion
How to run a batch file at logoff & some batch scripting help please
Hiya, I'd just like to run a simple batch file at logoff to backup some settings. I plan to use Robocopy, which is what i use to more thorough backups. Two questions: 1. How make it run by clicking Start > Shutdown? (i realise i could make a shutdown batch file and run it instead, but i'd...
Backup and Restore
Batch file request ...
Hello, I need bat file to detect xp or win7 (32 or 64) and then to copy ocx and dll files to appropriate system windir and afther copy to register them. my ocx files are in folder named OCX, and bat file is in main dir C:\SomeDir This is my bat file for register ocx files, but I dont know...
Software
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
batch file open file for program in the startup folder
I have a computer that is a drone specifically for an outside LED sign. This computer is designed to never shut off and doesn't have any other program on it besides Operating System and the sign software. I need to create a batch file that I can place in the "start-up" folder that will open the...
General Discussion
How to create a batch file that will move files based on the file type
How to create a batch file that will move files based on the file type? My Requirement : I need a batch file to copy all .doc files in all my HardDisk to a removable disk say (Z: drive) . Can anyone make it possible using a batch file?Please...Its urgent...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 08:18.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App