Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Help with Batch File  (Read 3757 times)

0 Members and 1 Guest are viewing this topic.

Done32

    Topic Starter


    Newbie

    • Experience: Familiar
    • OS: Windows 10
    Help with Batch File
    « 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.
    « Last Edit: March 13, 2019, 03:46:08 AM by Done32 »

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Help with Batch File
    « Reply #1 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.

    Salmon Trout

    • Guest
    Re: Help with Batch File
    « Reply #2 on: May 10, 2019, 11:04:22 AM »
    Unfortunately, many people think that CH is a free script-writing service.

    patio

    • Moderator


    • Genius
    • Maud' Dib
    • Thanked: 1769
      • Yes
    • Experience: Beginner
    • OS: Windows 7
    Re: Help with Batch File
    « Reply #3 on: May 10, 2019, 05:51:37 PM »
    + 1 +1...!!!
    " Anyone who goes to a psychiatrist should have his head examined. "

    Blisk



      Intermediate

      Thanked: 1
      • Experience: Familiar
      • OS: Windows 7
      Re: Help with Batch File
      « Reply #4 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