Solved

Batch script needed for same file name but different file types

Posted on 2016-11-18
4
22 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 83

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 83

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now