Find > Copy/Rename?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
vandentr
Posts: 1
Joined: 22 Jun 2018 14:34

Find > Copy/Rename?

#1 Post by vandentr » 22 Jun 2018 15:14

Hi Everyone,

I have a main folder that houses subfolders for each CNC job that is created by some CNC software we're using:

I:\MI-CNC\Backup_IMC\CNC_JOBS

For each CNC job, the software creates a job folder and places a text file (label.txt) in a "Labels" subfolder:

I:\MI-CNC\Backup_IMC\CNC_JOBS\XA049_ATA_PLASTIC\Labels\label.txt

I'm trying to figure out how to find and copy all of those individual label.txt files matching that folder path pattern in each job folder out to a collective "labels" folder, but renaming them to the job folder name.

So, using the job folder shown above, the logical process would be:

1) Find the label.txt file in the I:\MI-CNC\Backup_IMC\CNC_JOBS\XA049_ATA_PLASTIC\Labels folder
2) Copy it to I:\MI-CNC\Labels with the name XA049_ATA_PLASTIC.txt.
3) Repeat Step 1 on the next Job folder until complete.

The closest code I've come up with so far is this:

Code: Select all

@ECHO OFF
I:
CD MI-CNC\Backup_IMC\CNC_JOBS
for /r /d %%F in (labels\label.txt) do @for %%A in ("%%F\..\..") do copy %%F I:\MI-CNC\Labels\%%~nxA.txt
Is that the best\only way to do it?

Is there a way to force the operation to only use the CNC_JOB\[job name]\Labels\label.txt path?

Thanks for any insight!
TVB

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Find > Copy/Rename?

#2 Post by Squashman » 22 Jun 2018 15:47

vandentr wrote:
22 Jun 2018 15:14
Is there a way to force the operation to only use the CNC_JOB\[job name]\Labels\label.txt path?
Are you not already doing that with the CD command?

Code: Select all

@echo off

CD /D I:\MI-CNC\Backup_IMC\CNC_JOBS

for /D %%G in (*) do (
	IF EXIST "%%G\Labels\label.txt" copy "%%G\Labels\label.txt" "I:\MI-CNC\Labels\%%G.txt"
)

Post Reply