Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: batch for copying certain extensions  (Read 3105 times)

0 Members and 1 Guest are viewing this topic.

drpunkerz

  • Guest
batch for copying certain extensions
« on: June 10, 2005, 08:40:55 AM »
I'm trying to create a batch that moves .tif images from one directory to another, after those have copied it will then copy a .dat file to the same directory. Then move on to the next directory. I'm a little confused on how I go about this because all I've done is very basic, simple batches and I'm not sure how to begin with this task.
Below is an example of my directory structure.
------------------------------------------------------------------------

------------------------------------------------------------------------

I'm wanting the batch to go into the XXXX directory in the ProcessedBatches directory, copy every .tif file within that directory, move it to a destination directory, then copy the .dat file in the XXXX directory, move that into the destination directory,  and then move on to the next directory within the root of ProcessedBatches directory and repeat the same process.

------------------------------------------------------------------------

This may seem like an overwhelming amount of information, maybe it is. I'm not asking you to write the actual code for me (if you did i'd love you forever though.) .... I'm just looking for someone who may be able to point me in the right direction on where to begin (yes, I've browsed through the example batch files list from this website).

Thanks for any help you give me!

--drpunkerz

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: batch for copying certain extensions
« Reply #1 on: June 10, 2005, 10:00:08 AM »
There are different ways to do this. Many of them less cryptic. Below is just a template to give you an idea what needs to be done.

Code: [Select]

echo off
for /d %%a in (e:\ProcessedBatches\*) do (
     for /f "tokens=1-2 delims=." %%i in ('dir /b /a:-d %%a') do (
           copy %%a\%%i.tif DestinationPath
     )
)


Make sure the paths are correct before running. I'll let you handle the logic for the DAT file.

Hope this helps. 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

drpunkerz

  • Guest
Re: batch for copying certain extensions
« Reply #2 on: June 13, 2005, 11:01:40 AM »
The code you wrote out worked great but within each sub directory (i.e. 0001) it has the same naming scheme for each tif (image0001.tif, image0002.tif, etc) so this code only copies and overwrites about 20 times (one overwrite for each batch (or folder)....I added the /-Y option on the copy command so that it prompts me so that it doesn't overwrite but I have to hit n about a million times before it goes to the .dat copy process.

I'm only trying to move the tif's first, dat's second, wait roughly 4 minutes, delete the first subfolder (0001 in this example) move on to subfolder 0002 and repeat the same process. Now there is only one more problem...Each subfolder could possibly start out with 0082 and go through 0XXX... It varies. If I'm not making any sense please tell me. Thank you for your help

--drpunkerz

drpunkerz

  • Guest
Re: batch for copying certain extensions
« Reply #3 on: June 13, 2005, 04:17:08 PM »
To give you a better idea of what I'm trying to do... this is the code I've created thus far. I wasn't sure how to go around the code without doing a bunch of loops to check on some parameters but it gets the job done. Now all I need to do is figure out a way to remove a certain folder name after it has copied all the tif and dat files over to E:\fnis-iamodule03 ...

Code: [Select]

@echo off
cls

:modulecheck
IF EXIST e:\fnis-iamodule03\* (
GOTO modulecheck
) ELSE (
GOTO tif
)

:tif
for /d %%a in (e:\ProcessedBatches\*) do (
for /f "tokens=1-2 delims=." %%i in ('dir /b /a:-d %%a') do (
 copy %%a\%%i.tif E:\fnis-iamodule03  
)
)

:dat
for /d %%b in (e:\ProcessedBatches\*) do (
for /f "tokens=1-2 delims=." %%j in ('dir /b /a:-d %%b') do (
 copy %%b\%%j.dat E:\fnis-iamodule03  
)
)

IF EXIST e:\ProcessedBatches\* (
GOTO modulecheck
) ELSE (
GOTO end
)

:end
echo Import Finished!

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: batch for copying certain extensions
« Reply #4 on: June 13, 2005, 06:33:33 PM »
I'm a little unclear on some of your thinking, but your file looks fine. I guess I can't see what purpose those IF statements serve since the nested FOR's produce self-contained loops...one for the directories and one for the files.

To delete the folder: try using a RD before the last parenthesis of the DAT set.

If you have access to CHOICE (Win9x only) you can use that for your 4 minute timer otherwise you're SOL.

Use the /Y option on the COPY to suppress the prompts.

As batch files become more complex, Windows Script becomes a better option.

Hope this helps. 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

drpunkerz

  • Guest
Re: batch for copying certain extensions
« Reply #5 on: June 13, 2005, 09:59:57 PM »
Those if statements are for something I hadn't mentioned :p
Thank you a lot for your help!

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: batch for copying certain extensions
« Reply #6 on: June 14, 2005, 06:00:13 AM »
Now I understand. I had to do something similar to this for my photos. Each of them were numbered within their own subdirectory, but when I tried to move them into a common directory, the duplicates showed up. An added complexity was that fact that each directory had different levels of nesting.

The way to solve this was to write a recursive routine to follow each of the nested directories to their logical end before going on to the next directory.

To solve the duplicate problem, I had to keep counting each picture before I copied it and then use the count as part of the filename.

If this is what you're trying to do, I suggest a script. While writing a recursive batch file is possible, scripting, while still complex to follow, is still a better solution.

Hope this gives you some ideas. 8)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

drpunkerz

  • Guest
Re: batch for copying certain extensions
« Reply #7 on: June 14, 2005, 07:56:00 AM »
Yep. Learning perl right now :p