DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Select Range of Files Via Batch File  (Read 6,974 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Select Range of Files Via Batch File
« on: April 07, 2019, 07: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, 08:02 PM by nkormanik »

4wd

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

Spoiler (click to show/hide)
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 ;)
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: April 07, 2019, 01:16 PM by 4wd »

highend01

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

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: Select Range of Files Via Batch File
« Reply #3 on: April 07, 2019, 08: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

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Select Range of Files Via Batch File
« Reply #4 on: April 08, 2019, 09: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.
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: April 08, 2019, 09:49 AM by 4wd »

Original address: https://www.donationcoder.com/forum/index.php?topic=47466.0