I
I
i3core2022-03-16 22:47:50
cmd/bat
i3core, 2022-03-16 22:47:50

Move each file to its own folder and rename folder to name from filename?

There is a directory with a huge number of files, the files have the name: "Vasya_file_creation_date.ts", "Fedya_file_creation_date.ts", etc. the dates of creation of files in the names are different, so, it is necessary that all files with the name Vasya, but with different dates of the creation of files in the names, were transferred to a folder named Vasya, the folder should also be created by itself, the files from "Fedya" were transferred to the folder Fedya and etc., I think the landmark is the definition of the folder name and the identity of the files that need to be transferred to this folder is the first character "_".

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2022-03-17
@res2001

Iterate through all the files in a directory with a loop for.
You can select substrings in the file name using for /f, setting the appropriate separator.
Create directory md
Move file: move
For details:

for /?
md /?
move /?

You probably need delayed variable expansion:
setlocal /?

I
i3core, 2022-03-17
@i3core

I found it for a similar task:
The folder contains files
First.mp3
Second.mp3
Third.mp3
Fourth.mp3
the code is this:

@echo off
FOR %%f IN (*.mp3) DO md "%%~nf" & move /Y "%%f" "%%~nf\"

help me finish it for my task, this code transfers each file to a separate folder, but I need it without taking into account dates and extensions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question