Link to home
Start Free TrialLog in
Avatar of kcatnip9
kcatnip9

asked on

Batch script needed for same file name but different file types

Hello -

We have an internal process that creates an index file with a unique name ( 12345.idx)  and places it into a general directory. At some point - either hours or days - another file - which is a PDF - will have the same name (12345.pdf) - and it will be moved into the general directory.

I'm looking of a dos Batch file script that when it finds a match of the same file name for both types (12345.idx , 12345pdf) - it will MOVE these files from the general directory and move them into another directory for processing.

Thank you in advance!  ~k
Avatar of oBdA
oBdA

This is in test mode and will only display the "move" commands it would normally run. Remove the uppercase ECHO in front of line 10 to run it for real.
@echo off
setlocal enabledelayedexpansion
set Source=C:\General
set Target=C:\Processing
for %%a in ("%Source%\*.idx") do (
	echo Processing %%a ...
	if exist "%%~dpna.pdf" (
		echo ... pdf found, moving ...
		for %%b in (idx, pdf) do (
			ECHO move "%%~dpna.%%b" "%Target%"
		)
	) else (
		echo ... pdf not found, skipped.
	)
)

Open in new window

Avatar of kcatnip9

ASKER

Very close... thank you!

Sorry - The issue is now is the file name convention - which I  didn't list correctly. The PDF name is in the IDX file name.

12345.pdf.idx
12345.pdf

So when I run your script - it finds the IDX file  - but based on the batch output of the file name match - it lists the PDF file as 12345.pdf.pdf.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works perfect. Thank you for assisting so quickly. Awesome job!