Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-21
5
Medium Priority
?
309 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
[X]
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
  • 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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

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 …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

715 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