?
Solved

Batch script needed for same file name but different file types

Posted on 2016-11-18
4
Medium Priority
?
72 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 85

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 85

Accepted Solution

by:
oBdA earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

649 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