A
A
Arbitr2020-05-01 23:31:16
cmd/bat
Arbitr, 2020-05-01 23:31:16

How to move files in folders by even/odd parity of name?

There are files, many files, the names are numbers, like "1.txt" , "2.txt", "3.txt" etc. It is necessary to move files with even names to folder "a", and to folder "b" with odd ones. I wrote something like this, but I simply can’t write the file name to a variable.

@echo off
setlocal ENABLEDELAYEDEXPANSION
for %%i in (*.txt) do (
  set filename=%%i
  set filename=!filename:~2!
  set filename=!filename:~0,1!
  move filename.txt a
)

Please help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wisgest, 2020-05-02
@ArBitr_exe

Maybe something like this:

for /l %%d in (0 2 8) do move *%%d.txt a\
for /l %%d in (1 2 9) do move *%%d.txt b\

E
Eugene, 2020-05-02
@yellowmew

Posh

$folder='z:\test';$target=("$folder\a","$folder\b"); Get-ChildItem $folder -File | foreach { $p=[int]$_.BaseName % 2; Move-Item $_ $target[$p] }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question