topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Monday December 9, 2024, 11:21 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Select Range of Files Via Batch File  (Read 4666 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Select Range of Files Via Batch File
« on: April 07, 2019, 02:44 AM »
Consider the following files within a folder:

01.txt
02.txt
03.txt
04.txt
05.txt
06.txt
07.txt
08.txt
09.txt

Via batch file how can one select a range of files, say to be moved?

Example:

Move 03.txt through 07.txt from folder A to folder B.

Such a simple thing.  And yet....

Thoughts and suggestions appreciated.

Thanks!

Nicholas Kormanik

« Last Edit: April 07, 2019, 03:02 PM by nkormanik »

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: Select Range of Files Via Batch File
« Reply #1 on: April 07, 2019, 03:35 AM »
Regex: (0[3-7].txt) ... Now you just need to incorporate it into a PowerShell script.

Spoiler
ls R:\*|?{$_..... -match "0[3-7].txt$"}|%{mv $_......... D:\test}

Replace .... and ........ with the appropriate object properties.

Didn't think I'd make it that easy did you ;)

« Last Edit: April 07, 2019, 08:16 AM by 4wd »

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 188
    • View Profile
    • Donate to Member
Re: Select Range of Files Via Batch File
« Reply #2 on: April 07, 2019, 11:16 AM »
findstr has a regex mode as well...

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: Select Range of Files Via Batch File
« Reply #3 on: April 07, 2019, 03:11 PM »
@4wd, nicely done, indeed.  However, the example given is not so complicated, bear in mind.

Interesting that your suggestion, and of @highend01, is regex.  Pattern matching.  All 'intermediate' items must be matched.

Not exactly a through -- ordinal -- approach.

Using the usual Explorer route -- highlighting the first, shift-highlighting the last -- seemingly would be.  No command-line equivalent.


4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: Select Range of Files Via Batch File
« Reply #4 on: April 08, 2019, 04:41 AM »
However, the example given is not so complicated, bear in mind.

You can't "select" via a batch/script unless the items to be selected always follow some pattern.  If they don't then they're always going to have to be selected by hand unless you want to code something overly complicated for the task.

The other alternative is to get it right, (file management), the first time so it's not necessary to use all these small batch/script files in the first place.

As @Shades said, get a decent file manager and stop screwing around with 101 dinky little one shot batch/script files.
« Last Edit: April 08, 2019, 04:49 AM by 4wd »