Solved

How do I delete a file based on the name of another file

Posted on 2011-03-21
5
300 Views
Last Modified: 2012-06-22
I have the script pasted below:

It will find files containing that string.  In the last exmple, it moved a file named xx12.hw.  There is always a companion file with this naming scheme x'#'
So, for the example above xx12.hw would have a companion file named x12 (no extension)

How do I get this script to find the xx'#'.hw files and move it, then move the x'#' version of the same file?  The x'#' file doesn't have anything in it, so I can't search against it.  I have to basically just move it based on the name of the other file found.  

Thanks!
di@ECHO OFF
:looptop
cd\
i:
cd\
cd drs\queues\automation\action
rem
pushd i:\drs\queues\automation\action
for /f "tokens=*" %%F in ('dir /b/a-d') do (
type %%F | find "TextToSearchFor" > nul
if not errorlevel 1 move "%%F" c:\BadQueueEntries
)
popd
sleep 10
goto looptop

Open in new window

0
Comment
Question by:weklica
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
change this:
  if not errorlevel 1 move "%%F" c:\BadQueueEntries

to this:
  if not errorlevel 1 move "%%~nF*" c:\BadQueueEntries

It will move all files with that prefix.
0
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
hmm, you may or may not want to add the "dot" like this:  "%%~nF.*"  ... depending on whether there are other files with similar names like "xx12.hw" and xx120.hw"
0
 

Author Comment

by:weklica
Comment Utility
Yes, there would be similar files like that.  It would need to be xx12.hw and x12 exactly in this particular example.

So, would this one do that then?

if not errorlevel 1 move "%%~nF*" c:\BadQueueEntries
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 total points
Comment Utility
then you need to add the dot like this:  "%%~nF.*"

and if that doesn't work, then do it the long way:

if not errorlevel 1 (
  move "%%F" c:\BadQueueEntries
  move "%%~nF" c:\BadQueueEntries
)
0
 

Author Closing Comment

by:weklica
Comment Utility
Thanks very much
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

16 Experts available now in Live!

Get 1:1 Help Now