Solved

Batch script needed for same file name but different file types

Posted on 2016-11-18
4
54 Views
Last Modified: 2016-11-18
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
0
Comment
Question by:kcatnip9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 84

Expert Comment

by:oBdA
ID: 41893612
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

0
 

Author Comment

by:kcatnip9
ID: 41893691
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.
0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 41893742
@echo off
setlocal enabledelayedexpansion
set Source=D:\Temp
set Target=C:\Temp
for %%a in ("%Source%\*.idx") do (
	echo Processing %%a ...
	if exist "%%~dpna" (
		echo ... pdf found, moving ...
		ECHO move "%%~fa" "%Target%"
		ECHO move "%%~dpna" "%Target%"
	) else (
		echo ... pdf not found, skipped.
	)
)

Open in new window

0
 

Author Closing Comment

by:kcatnip9
ID: 41893793
Works perfect. Thank you for assisting so quickly. Awesome job!
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question