Computer Hope

Microsoft => Microsoft DOS => Topic started by: Done32 on March 12, 2019, 03:54:50 PM

Title: Help with Batch File
Post by: Done32 on March 12, 2019, 03:54:50 PM
Hi,

I'm in need of help writing a batch file. I'm running Windows 10. I need a batch to delete the contents of a subdirectory if it no longer has a certain type file in it.

Main directory "T:\Series

Subdirectories T:\911
          T:\ 911 files to be removed
T:\run
          T:\ Run Files to be removed
T:\Test 3
         T:\ Test 3 Files to be removed
about 75 total Total

Delete all files in "Files to be removed"directories if it does not contain a *.inf file in the directory. If it does contain the *.inf files the directory remains intact. The Main directory "series" and Subdirectories " 911, Run, Test3  Stay intact... Not deleted.

Thanks in advance for your help.
Title: Re: Help with Batch File
Post by: Geek-9pm on May 10, 2019, 10:54:10 AM
From dictation.
Hello, this is not a quick solution to your problem.
A number of people have looked at your post but have not giving you any kind of reply. Therefore I thought I would deeply say something in an effort to be helpful.
For myself is extremely difficult to debug batch files that tend to be rather involved. Mostly because the conventions that are used in that file programming are not self-evident to most programmers who have come from another language.
This is intended to be constructive criticism. If it were me, I would start out with a broad outline of my objective. In some cases using somebody else's code might be the best solution. But not always. One of the things you have to do in programming is to analyze ahead of time all the things that might go wrong. .
Although batch file cando a lot of things, it can become awkward .  Other script languages are much easier to read. I'm thinking of a language such as VBScript. With Vb Script there is a way to identify a things with descriptive names  inside the program script.
So for me, that would be enough reason to want to use Vb Script or a similar programming language that has a way to refer to variables and methods with names that make sense, I think that can be done in batch file programming, but  takes more effort. I think.
It might be the batch file you have chosen can be adopted. Or it may be necessary to write a completely new program. Possibly in batch or maybe in some other scripting language that is available in Windows.
Again, this is meant to be helpful. I hope this is of some help.
End of dictation.
Title: Re: Help with Batch File
Post by: Salmon Trout on May 10, 2019, 11:04:22 AM
Unfortunately, many people think that CH is a free script-writing service.
Title: Re: Help with Batch File
Post by: patio on May 10, 2019, 05:51:37 PM
+ 1 +1...!!!
Title: Re: Help with Batch File
Post by: Blisk on May 14, 2019, 02:17:04 AM
Since I get alot of help here especially from Salmon.
I will help you

Code: [Select]
if exist "T:\Series\911\yourfile.dat" (goto 911CON) else (goto CON1)
:CON1
rd /S /Q T:\Series\911
:911TCON
if exist "T:\Series\run\yourfile.dat" (goto RUNTCON) else (goto CON2)
:CON2
rd /S /Q T:\Series\run
:RUNTCON
if exist "T:\Series\test3\yourfile.dat" (goto End) else (goto CON3)
:CON3
rd /S /Q T:\Series\test3
:End