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
Solved

Batch script needed for same file name but different file types

Posted on 2016-11-18
4
52 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
  • 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

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

Suggested Solutions

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…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 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