Solved

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

Posted on 2011-03-21
5
303 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

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…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

789 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