Create folder from file name and move file into

is it possible to create a button that creates folder from a file name in the folder its located and then move the file into it? if so how?

Yes.

You can use an RE for example. to match the pattern you want from the file name, to be used as the folder name. Then, the rename portion will include two backslashes in a row, which will signify the slash between the new directory name and file name.

Test it out in the Regular expression rename area.

Windows does not allow a directory to have the exact same name as a file, there has to be at least one different character.

Two possible renames that come very close:

File: test.txt => Directory: -test.txt

<?xml version="1.0"?>
<button display="label">
	<label>Move to Same Name Subfolder 1</label>
	<tip>Move File to SubFolder with Same Name 1</tip>
	<icon1>139</icon1>
	<function type="normal">
		<instruction>Rename PATTERN &quot;*&quot; TO &quot;-{name}\*&quot; FILEINFO</instruction>
		<instruction> </instruction>
	</function>
</button>

File: test.txt => Directory: test

<?xml version="1.0"?>
<button display="label">
	<label>Move to Same Name Subfolder 2</label>
	<tip>Move File to SubFolder with Same Name 2</tip>
	<icon1>139</icon1>
	<function type="normal">
		<instruction>Rename PATTERN &quot;(.*)\.(.*)&quot; TO &quot;\1\\\1.\2&quot; REGEXP </instruction>
		<instruction> </instruction>
	</function>
</button>

Nothing says you have to create the folder with the same name first. Either:

rename the file
create the new folder with the desired name
move the file with the original name into the folder

or

Create a new folder
move the file into the folder
rename the folder

THANK YOU!!! for both examples and also ideas from both of you.

after seeing how the process works i was able to customize the regex so that it grabs the name before the dash in music / video / ebook files and use that at the folder name.. that way it organizes authors / artists of the same name and what not..

example: 3rd Eye Blind - Compilation.mp3 ==> 3rd Eye Blind\3rd Eye Blind - Compilation.mp3

Rename PATTERN "([^-]*) - (.*)" TO "\1\\\1 - \2" REGEXP AUTORENAME

Just so you have more options. This button was posted by someone months/years ago.

Select 1 or many files and click the button, A dialog will open asking you to name the new folder (it takes the name from the first file), Click OK. Creates the new folder and moves the files into it.

The Button:

<?xml version="1.0"?>
<button backcol="none" display="both" hotkey="shift+up" icon_size="large" textcol="none">
	<label>New Folder From Files</label>
	<tip>Select all files you want moved to new folder, then click this button. Name new folder.</tip>
	<icon1>#layoutload</icon1>
	<function type="batch">
		<instruction>@nofilenamequoting</instruction>
		<instruction>@runonce:@set dirname={dlgstringS|Enter name of folder to move selection into|{file$|noext}}</instruction>
		<instruction>Copy MOVE HERE FILE=&quot;{file$}&quot; CREATEFOLDER=&quot;{$dirname}&quot;</instruction>
		<instruction>@nodeselect </instruction>
	</function>
</button>

The Code:

@nofilenamequoting
@runonce:@set dirname={dlgstringS|Enter name of folder to move selection into|{file$|noext}}
Copy MOVE HERE FILE="{file$}" CREATEFOLDER="{$dirname}"
@nodeselect 
1 Like