Solved

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

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

635 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