Moving files outside their folders

Hello,

I'm trying to create a button to move files outside their folders giving them the folder name with its respective file's extension:

COPY FILTER *.{$exts} MOVE "&PATH&\*" AS "&NAME&.{ext?}"

Unfortunately, i'm not able to realize how to extract just the file extension from the original filename on that copy command.

Could someone give me a hand please?

Hello MrC, thanks for your reply.

First of all, it's fun to see there is another thread started this same month asking nearly the same question - i did used G to search but not the forum itself.. In any case, the RENAME command is what i first tried by checking at the docs but that didn't work properly, specifically i've used:

GO &NAME&
SELECT *.{$exts}
RENAME PATTERN ".*\.{$exts}" TO "&NAME&.\1" REGEXP
COPY MOVE *.{$exts}
GO Back
DELETE "&PATH&" FORCE QUIET ALL

Problem is when selecting multiple folders, it just work on the first one - i guess cause of the Go command required for selecting files for the RENAME command, unless im missing something. So, i was hoping this could be achived from the source path with a single COPY procedure. :-/

I don't know how to do this in one shot. I can do it in Flat View with the files selected:

@filesonly
Rename FILEINFO PATTERN "*" TO "..*"

Oh well, maybe "outside their folders" wasn't the proper sentence, actually i'm trying to move them to the destination lister.

In any case, it may worth pointing out that i have been using another button for ages, which worked great for the purpose:

paren.bat "&NAME&" Copy MOVE "{s}\&NAME&\&NAME&*" DELETE "{s}\&NAME&" FORCE QUIET ALL

Being the paren.bat script as follow:

[code]
@echo off

set name=%~1

CD "%name%"
RENAME *.pdf "%name%.pdf"
RENAME *.chm "%name%.chm"
RENAME *.nfo "%name%.nfo"[/code]

However, the other day i just wanted to add "avi" and "mkv" to the list, and noticed it doesn't work if the filename (referenced as &NAME&) contains spaces. I checked the rename takes place on such case, and the file(s) removed, so the problem here should be the COPY command somehow (due the use of the wildcard at the end of the string, i guess)

So... i thought i could just get rid of that whole .bat-based button and use a "native" one instead with the FILTER arg, and it'd work like a charm if it weren't due the file extension thing :-/

Well, thanks for your help anyway, MrC.

You need to add @nofilenamequoting to the button if you are adding the quotes yourself, otherwise you'll get two lots of quotes when things contain spaces.

Hi Leo, thanks to your tip i've just realized what the real problem is... the name is something like "Title [HDTV][2013]" so, those [] are conflicting with wildcards - is there some way to escape them?

{file|escwild} will be like {file} but with the wildcard characters escaped.

Erm, somehow that isn't working yet. The command being issued is:

Copy MOVE "D:\Peliculas\\sdasda '[2342']\sdasda '[2342']*"

Some clue? :-/

What's the actual command that you're running? (Or commands if you're using both a user command and another command to run it.)

You're correct, i'm using two steps.

Toolbar button:

@nofilenamequoting 
paren "{o}" "{s}" "{o|escwild}"

paren user-command:

@runmode hide
CD "&PATH&\"
paren.bat "&NAME&"
Copy MOVE "&PATH&\&NAMEE&\&NAMEE&*"
//DELETE "&PATH&\&NAME&" FORCE QUIET ALL

(Template: NAME/A,PATH/A,NAMEE/A)

Hi there...

I ended up using the following, if someone cares :slight_smile:

Button:

@nodeselect MFCTODWFN {o} {f} Set SOURCE=toggle SELECT *-1,x,1-* RENAME PATTERN "(.*)-1,x,1-.*\.(\w{3})" TO "\1.\2" REGEXP

User-Command:

COPY MOVE "&PATH&\*.{$exts}" AS "&NAME&-1,x,1-*" DELETE "&PATH&" FORCE QUIET ALL

Probably isn't the more optimal way, but hey i doesn't have issues with wildcards.

Cheers.

  • It doesn't - i meant

i'm blind or we can't edit posts?

See this FAQ.

Regards, AB

Makes sense, thank you AB.

[quote="diegocr"]You're correct, i'm using two steps.

Toolbar button:

@nofilenamequoting 
paren "{o}" "{s}" "{o|escwild}"

paren user-command:

@runmode hide
CD "&PATH&\"
paren.bat "&NAME&"
Copy MOVE "&PATH&\&NAMEE&\&NAMEE&*"
//DELETE "&PATH&\&NAME&" FORCE QUIET ALL

(Template: NAME/A,PATH/A,NAMEE/A)[/quote]

You may not need to escape anything but the last component of the path (I'm not sure, though). (On the other hand, if you need all parts of the path to be escaped, then the {s} part (PATH variable) would need it as well.)

There's also an extra \ or two in there since {s} will have a \ on the end. You might want to use {s|noterm} to prevent it and keep the slashes in the command itself for clarity.

By the way, you might want to make sure the delete line at the end is safe. I'm not sure exactly what this will be used on or where things are being moved to here, so it might not matter, but the example in the Buttons forum for moving things up one level has a discussion about why it may be better to use the DOS rmdir command to clean up folders after moving everything in them around. Using rmdir lets you avoid deleting directories which are not empty.

(In the "moving things up one level" case, you might have C:\A\A and move everything in C:\A up one level. You'll still have files in C:\A afterwards because the A directory got moved up one level.)

Hi Leo,

I just wrongly assumed everything had to be escaped, and since i knew the path didn't contain any special char i just did it that way to test. It quite makes sense now that you said it that just the last part should be escaped. In any case, i wanted to get rid of the .bat and finally i did it.

As for the purpose of the button, i download everything to some folders inside D:\ and from there i manually organize them, moving the files to some other places of the D:\ drive. The button is to move the files which matter, and deleting everything else. So, the folders aren't in fact empty after the button's action is executed, they end up with some other files i don't care about (such as .txt, .diz, or .url)

Well, thank you all for your help.