To avoid problems with spaces in the path / file names, specify all links to them twice.
The reason for including a line at the end of the folder in your code is an attempt to create a folder with the same name as the file (in the code, you do not delete the extension), and you cannot have two elements (files or folders) inside the folder with the same name.
@echo off for %%a in ("c:\folder\*") do ( if not "%%~fa"=="%~f0" ( if not exist "%%~dpna\" echo md "%%~dpna" if exist "%%~dpna\" echo move /y "%%~fa" "%%~dpna" ) )
For each file in the specified folder
%%~fa = full path of the file being processed
%~f0 = full path to the batch file
%%~dpna = disk name, path and file name without the extension of the current file that is running
In this code, the reason for the third if is to check if the possible creation of the previous folder failed. If you have a file without an extension, you cannot create a folder, since it will have the same name as the file, and this is not allowed.
There are echo commands in the code before md and move to indicate that it will be executed. If the output is correct, delete echo to make it work.
MC ND
source share