What do you want to do in the end
·I want to move only specific extension files in the target folder (including subfolders) to the specified folder
·If a file with the same name exists, I would like to give it serial numbers instead of overwriting it
·I was able to confirm the movement of the batch file that moves specific files to the specified folder, but if a file with the same name exists, it will be overwritten to one file
·If there is a file with the same name, I don't know how to add conditions by giving consecutive numbers instead of overwriting
·At what stage should the conditional branch be added if a file with the same name exists? When creating list.txt? Or when you're processing files one line at a time?
At what stage should the conditional branch be added if a file with the same name exists? When creating list.txt? Or when you're processing files one line at a time?
If you add a conditional branch when creating the list.txt, it will be overwritten if it is newly created before creating the file, so you should add it when you process it.
If there is a file with the same name, I don't know how to add conditions to add consecutive numbers instead of overwriting
Powershell is better suited for detailed operations such as obtaining serial numbers, so I made an example implementation with Powershell.
At first, I tried to implement it as a bat file, but I was frustrated because extracting serial numbers was troublesome.
If you want to see the bat file even if it's a half-baked implementation, please refer to the answers before the revision from the history.
Git Bash is recommended because there are more Bash users than PowerShell users, so you can gain more knowledge.Perl is also included in the Git Bash.With Perl, you can do the whole thing.
D:\test contains subdirectories called
B.In Git Bash,
D:\test is written as
/d/test, so enter
ccc.out, and move
Prepare the following Perl script file:
Run this script within the Git Bash
/d/test/.The execution commands are as follows:
When you run it, you will see the following:
./A/aaa.txt to ./B/aaa.txt Move ./A/bbb.txt to ./B/bbb_3.txt Move ./A/ccc.txt to ./B/ccc_1.txt
In fact, only
© 2022 OneMinuteCode. All rights reserved.