#1 2022-12-09 20:52

snazzy
Member
Registered: 2022-12-09
Posts: 3

ReNamer command line: "add files in this folder and it's subfolders"

hi,

been fumbling around with ReNamer as a rightclick option. I want the following:

*rightclick on a folder that i want the file-contents renamed of,
*select the rightclick-menu option that I will add under 'Rename here' or 'Rename this folder' (something like that)
*selecting that option then calls a cmd-line script
*that script adds all files in the folder, and underlying subfolders (nested and only second level)

Now, the normal installation provides this function, obviously. But I want to deploy a chain of several programs and scripts, of which Renamer is only a part, therefor I want to run it from command line and unattended. Other functions in my chain following ReNamer will be 'move all files from subfolders to basefolder' and 'remove all empty folders from the basefolder'.

My question is not about the rightclick deployment, my question is: how do I add all files in a folder and it's subfolders to Renamer in commandline mode?

I do have this, this does start renamer, but does not yet add all the files in the folder that I run the batchfile from, which is what I want:

c:
cd\
cd program files (x86)
cd renamer
renamer.exe /preset "Default"



Thanks so much in advance, kind regards, snazzy

Last edited by snazzy (2022-12-09 20:58)

Offline

#2 2022-12-09 22:38

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: ReNamer command line: "add files in this folder and it's subfolders"

Hi snazzy,

just have a look at the command line options

BTW: you can cd into a directory directly by stating the complete path:

c:
cd "\program files (x86)\renamer"
renamer.exe /preset "Default"

But neither the preset nor your files will be located in this folder. So you can just start ReName with a full qualified path:

"C:\Program Files (x86)\ReNamer\ReNamer.exe" /preset "Default"

Or with using the environment value:

"%ProgramFiles(x86)%\ReNamer\ReNamer.exe" /preset "Default"

Last edited by jogiwer (2022-12-09 22:48)

Offline

#3 2022-12-10 10:56

snazzy
Member
Registered: 2022-12-09
Posts: 3

Re: ReNamer command line: "add files in this folder and it's subfolders"

hi jogiwer,

thanks a bunch, I changed the script according to your suggestions. It works now: when I start my renamerscript.bat in the folder of which I want the files renamed, they indeed show up in ReNamer.

"C:\Program Files (x86)\ReNamer\ReNamer.exe" /preset "Default" "*.*"

However: the files in the subfolders are not renamed with this commandline. How can I add subfolders to it?

Next step will be to add them as a rightclick option to Windows shell so that the application of the script becomes versatile (now I can only rename files in the folder the batchfile is in). It comes in two files (a .reg file and a batchfile) of which I do have an example in the form of 'Fast Delete this folder'. I will present them here and change accordingly to match the new command:

****

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Fast Delete]

[HKEY_CLASSES_ROOT\Directory\shell\Fast Delete\command]
@="cmd /c \"cd %1 && delete.bat\""

****


@ECHO OFF
ECHO Delete Folder: %CD%?
PAUSE
SET FOLDER=%CD%
CD /
DEL /F/Q/S "%FOLDER%" > NUL
RMDIR /Q/S "%FOLDER%"
EXIT

****

When it comes to the Registryfile, I can change 'delete.bat' to 'renamescript.bat' and put my 'renamescript.bat' file in c:\windows. But what are those switches:   /c \"cd %1 &&    ?

When it comes to the batchfile, I can change things accordingly (say 'delete folder' by 'rename folder' etc). But what is this switch about: %CD% ?

****

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\ReName here]

[HKEY_CLASSES_ROOT\Directory\shell\Rename here\command]
@="cmd /c \"cd %1 && renamerscript.bat\""

****

@ECHO OFF
ECHO Rename Folder: %CD%?
PAUSE
SET FOLDER=%CD%
CD /
renamerscript.bat
EXIT


I am asking quite a lot, I know. Thanks for helping me out in this, greatly appreciated.

Kind regards, snazzy

Last edited by snazzy (2022-12-10 11:07)

Offline

#4 2022-12-10 14:54

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: ReNamer command line: "add files in this folder and it's subfolders"

Wow, that is a lot of stuff.

Passing folder via command line:

It thought the "*.*" is just to restrictive as it contains a dot. But "*" and "*\*" also won't dive into the folders. So I am clueless here - maybe Denis or Stefan could help ...

Batch coding under windows:

All the rest is more into windows than ReNamer ... but I'm trying to give some hints.

If you are in a shell you could make use of the help command to see the options:
Just try these:

help echo
help del
help set
help cmd

In batch the string with % are replaced by the according value from the environment:
%CD% will give you the current dir

Further:
cmd - will start a shell (non interactiv in this case)
/c - is the option for cmd which command to execute
\" these quotes inside outer quotes need to be escaped
\"cd %1 && delete.bat\" - the command is composed from two commands joined by "&&" (i.e. and). So: "cd %1" AND than "delete.bat"
%1 - the value of the first parameter. Used by the context menu this will be the name of the file or folder ...

In batch coding you'll have to fiddle around with the % variables. In some cases you'll need one % in other cases it is two: %name vs. %name%

Conclusion:

I would go for a batchfile which takes a parameter. So there is no need to cd into the target dir.

The registry entry would end up like one of these:

@="cmd /c \"myscript.bat %1\""
@="cmd /c \"C:\path\myscript.bat %1\""

Inside your batch you could work with this as %1 directly or set a variable to its value:

@ECHO OFF
SET param=%1
"%ProgramFiles(x86)%\ReNamer\ReNamer.exe" /preset "Default" "%param%\*"
EXIT

Last edited by jogiwer (2022-12-10 14:55)

Offline

#5 2022-12-10 17:34

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: ReNamer command line: "add files in this folder and it's subfolders"

https://www.den4b.com/wiki/ReNamer:Command_Line
....will load the preset with the name "MyRules", and will add contents
of folder "C:\Folder" (depending on the default settings incl. Filter_settings).

https://www.den4b.com/wiki/ReNamer:Filter_settings
Include subfolders    -- Loads contents from all subfolders recursively.

https://www.den4b.com/wiki/ReNamer:Using_presets
A "preset" is a set of rules that is saved with a user-defined name.
It can optionally save the Filter setting also.





HTH wink
 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#6 2022-12-10 18:11

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: ReNamer command line: "add files in this folder and it's subfolders"

I had no time, but then I start reading and now I want to contribute a bit at least:



First & Second >> will execute first First, and next Second
First && Second > will execute first First, and, if errorlevel of First was 0, next execute Second too. Else not.



%variable% are environment variables.
!variable! works if "delayed expansion" is enabled, to get the modified content of vars, right during the batch execution.
%v is a variable with the FOR command (use %%v inside of a batch)
for /f "tokens=2,3* delims=," %x in (foo.txt) do ... on cmd console window.
for /f "tokens=2,3* delims=," %%x in (foo.txt) do ... inside of a batch file.



If you use:
SET param=%1
"%ProgramFiles(x86)%\ReNamer\ReNamer.exe" /preset "Default" "%param%\*"

it's advisable to check with:
ECHO %param%
to see if there are doubled quotes at the end, like >>> ""%param%"\*"

For to remove quotes from %1, use:
SET param=%~1
then it's save (but also it's mandatory now if there could be spaces)  to use:
"%param%\*"



@="cmd /c \"cd %1 && renamerscript.bat\""
could be adjusted to:
@="cmd /c \"cd \"%1\" && renamerscript.bat\""
to quote folder names if they could contain spaces.



HTH


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#7 2022-12-10 18:13

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: ReNamer command line: "add files in this folder and it's subfolders"

Ok,

had to retry it as I thought I did it that way ...

But my failure was to use a wildcard. So adding "path\*" would only add files to renamer - even if "path" contains subfolders. And "path\*\" didn't add anything.

So you have to:

  1. name the directory without using wildcards

  2. set the filter settings to "Include subfolders" if you want to add them too

What all of this can not handle is snazzys wish to only in include files down to second level ...

If only a specific set of folders has to be added this has to be done from your script (as far as I know now):

@ECHO OFF
SET folder=%1
SET rn="%ProgramFiles(x86)%\ReNamer\ReNamer.exe"
%rn% /preset "Default" "%folder%"
for /D %%S in (%folder%\*) do %rn% /enqueue %%~fS
EXIT

The setting to "Include subfolders" has to be switched off though.

Offline

#8 2022-12-10 18:28

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: ReNamer command line: "add files in this folder and it's subfolders"

Ah - working and commenting parallel right now ;-)

Stefan wrote:

If you use:
SET param=%1
"%ProgramFiles(x86)%\ReNamer\ReNamer.exe" /preset "Default" "%param%\*"

it's advisable to check with:
ECHO %param%
to see if there are doubled quotes at the end, like >>> ""%param%"\*"

For to remove quotes from %1, use:
SET param=%~1
then it's save (but also it's mandatory now if there could be spaces)  to use:
"%param%\*"



@="cmd /c \"cd %1 && renamerscript.bat\""
could be adjusted to:
@="cmd /c \"cd \"%1\" && renamerscript.bat\""
to quote folder names if they could contain spaces.

You are right with the quotes ... Actually I am not sure what will be made out of the cmd call:

cmd /c "cd "C:\path with spaces\" && renamerscript.bat"

Will the quotation arround the path work or not? Windows is so much different than all the unix shells.

And yes - you are right about the quotations on parameters - so %~1 is to be preferred but than quotations have to be added again were needed.

Last edited by jogiwer (2022-12-10 18:30)

Offline

#9 2022-12-10 18:38

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: ReNamer command line: "add files in this folder and it's subfolders"

jogiwer wrote:

... Actually I am not sure what will be made out of the cmd call:

cmd /c "cd "C:\path with spaces\" && renamerscript.bat"

Will the quotation arround the path work or not? Windows is so much different than all the unix shells.

Took a look at "help cmd". In this case the outer quotation marks will be ignored completly:

cmd /c cd "C:\path with spaces\" && renamerscript.bat

Thus the path parameter will get its "!

Offline

#10 2022-12-10 18:42

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: ReNamer command line: "add files in this folder and it's subfolders"

jogiwer wrote:

What all of this can not handle is snazzys wish to only in include files down to second level...



With VBS script I have counted the number of "\" in the path to stop at a given number of "\"s.
For PowerShell there is a script somewhere with key word "deep"

For batch me think you can could use the FOR command?:
FOR /L %%parameter IN (start,step,end) DO command
FOR /L %%parameter IN (0,1,2) DO ( your commands here )




 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

Board footer

Powered by FluxBB