We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

Additional enhancements to a Windows batch file (Powershell option is welcome)

107 Views
Last Modified: 2020-12-09
Hello all,

I am using a batch file to automatically sort 1000's of files into their respective folders, using the following DOS (Windows 10) batch:

@echo off
set path1=W:\_Pub\__Staging\

call :DoMove "_DNA_nuc\" "*dATP002* *dTTP801*"
call :DoMove "_enzyme\" "*ligase* *plasm* *foo*"
call :DoMove "_Protoalas\Stage1\" "*proto??phase*"

exit /b

:DoMove [dest-folder] [file-patterns]
   REM set path1 = ""
    if not exist %path1%%~1 md %path1%%~1
    for %%a in (%~2) do (
      echo Moving "%%~a" to %path1%%~1
      move "%%~a" %path1%%~1 >NUL
   )
    exit /b

This batch file works exceptionally well, however, it cannot move files with the following characteristics:
  • Files with more than one keyword string in non-fixed order.
    Example: keywords: "proto" and "plasm" is any position within the file name.
  • Files with more than one keyword string, but NOT containing a specific string.
    Example: keywords: "proto" and "plasm" is any position within the file name, but NOT containing the string, "Stage2".

Basically, I am looking for a way to incorporate some rudimentary Boolean into this batch file. Is this even possible? 

Thank you
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 16 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE