Answer the question
In order to leave comments, you need to log in
Need to sort all files by folders.?
I'm not very strong in CMD,
there are files in the folder C: \ TEMP \
A20210423.2300+0300-0000+0300_ATS_60_01_GU.XML.gz
a20210423.2300+0300-0000+0300_60_02_guln.xml.gz
a20210423.23.23.23.23.23.23.23.23.23.23.23.23.23.23.23.23.23.23.23.23AL .xml.gz
A20210423.2345+0300-0000+0300_ATS_60_02_GULN.xml.gz
you need to create folders by file name from the end of the file name and decompose into folders.
Should happen here
folder with: \ the Temp \ ATS_60_01_GU
A20210423.2300 + 0300-0000 + 0300_ATS_60_01_GU.xml.gz
A20210423.2345 + 0300-0000 + 0300_ATS_60_01_GU.xml.gz
folder C: \ the Temp \ ATS_60_02_GULN
A20210423.2300 + 0300- 0000+0300_ATS_60_02_GULN.xml.gz
A20210423.2345+0300-0000+0300_ATS_60_02_GULN.xml.gz
Answer the question
In order to leave comments, you need to log in
Powershell
Set-Location c:/temp
$groups = (Get-ChildItem A*).Name | group-object -property {$_.Substring(30,$_.Length -37)} -ashashtable -asstring
$groups.Keys | foreach-object {
$folder=$_; $groups[$folder] | foreach-object {
new-item -itemtype file -path "$folder/$_" -force
move-item -path $_ -destination "$folder/$_" -force
}
}
cd c:/temp;$g=(dir A*).Name | group {$_.Substring(30,$_.Length -37)} -AHT -asstring;$g.keys | %{$f=$_;$g[$f] | %{ni -type file -path $f/$_ -force; mv $_ $f/$_ -force}}
There are several problems in your task:
1. Remove the double expansion. If the extension is always fixed, then you can simply use the replace operation that is in set. If the extension is not fixed, then 2 procedure calls (or nested for loops) and the %%~dpnI
.
2. Select a substring in the file name. The file name itself can be distinguished from a path from which extensions have already been previously removed using the modifier %%~nI
. Then you can use a loop for /f
to split the name into component parts, specify the characters "+", "-", "_" as a separator.
Files are bypassed in the for loop.
For reference see:
:: тут описание модификаторов и описание разновидностей for
for /?
:: операция замены, арифметика, ...
set /?
:: Вам нужно будет, скорее всего использовать режим отложенного расширения переменных: ENABLEDELAYEDEXPANSION. Разберитесь с ним, это достаточно тонкий и не очевидный момент
setlocal /?
:: просто так
if /?
:: Каждая команда cmd имеет свою справку используйте ее. Это основной источник информации по программированию cmd
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question