Solved

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

Posted on 2011-03-21
5
304 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
ID: 35182341
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
ID: 35182361
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
ID: 35182443
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
ID: 35182462
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
ID: 35182575
Thanks very much
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 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