How to append folder name using a .bat file

Bulk Rename Utility How-To's

How to append folder name using a .bat file

Postby killerfrog423 » Mon Jan 04, 2021 2:34 pm

looking to use a .bat file to append folder name to .txt files. this will be on a usb to copy in multiple folders on multiple machines.

FOR %%f IN (*.txt) DO ("D:\Bulk Rename Utility\BRCUnicode64\BRC64.exe") /removename /appendfolder:P: -:1 /execute

everything I have tried doesn't seem to work. any help will be appreciated
killerfrog423
 
Posts: 5
Joined: Mon Jan 04, 2021 2:27 pm

Re: How to append folder name using a .bat file

Postby therube » Mon Jan 04, 2021 5:30 pm

Because you have a space in there, you need to enclose it in quotes.
Not sure of the exact syntax, but BRC seems to be liberal in what it allows, so something like this should work:
Code: Select all
brc32.exe   /removename  /appendfolder:P:"   -":1

Run without the /execute - initially, to verify that your wanted results are what you get.
(I've stuck a couple extra spaces in my example.)

"What you get...".
I'm thinking, that what you are going to get are duplicated file names (assuming you've got more then one .txt file per directory) - which isn't going to work out too well?
therube
 
Posts: 964
Joined: Mon Jan 18, 2016 6:23 pm

Re: How to append folder name using a .bat file

Postby Luuk » Tue Jan 05, 2021 7:42 am

Greetings to everyone.. Im very much agree with therube, because always its best to experiment without the /execute.
Also, please to remember /pattern:*.txt conducts only the text files, so not using FOR unless having more commands except for only brc64? There is also /nodup to append _# to the names if they get invented to exactly the same names. Also the "P" inside /appendfoldername is prefix, so the "S" can be for suffix.

This another experiment without /removename and /execute, but also having /recursive...
Code: Select all
"D:\Bulk Rename Utility\BRCUnicode64\BRC64.exe" /dir:"UsbDrive:\FolderPath" /recursive /pattern:*.txt /appendfolder:"P: -:1"
Im thinking the most important is /dir: because we cant see the whole batch, so we are not knowing your directory? If the experiments cannot succeed, please to give example for the new names and how to copy in "multiple folders on multiple machines".
Luuk
 
Posts: 132
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to append folder name using a .bat file

Postby killerfrog423 » Thu Feb 11, 2021 12:10 am

hello!
sorry for the late reply, with yalls help i was able to get it working somewhat.

FOR /R %%A IN (*.txt) do ( "C:\Program Files\Bulk Rename Utility\BRCUnicode64\BRC64.exe" /pattern:*.txt /appendfolder:P:-:1 /execute )

everything works but one thing i can't seem to get right is this.

EX: foldername\1234.txt gets renamed to foldername-1234.txt and there is a bug adds the folder name multiply times if there is a number first.
what I am trying to get right is this foldername - 1234.txt

if I add spaces in the appedfolder:P: - :1 it does not work.
killerfrog423
 
Posts: 5
Joined: Mon Jan 04, 2021 2:27 pm

Re: How to append folder name using a .bat file

Postby Luuk » Thu Feb 11, 2021 4:18 am

Still must remove the FOR command! Its telling brc64.exe to start and stop again for every .txt file.
So with four .txt files in current directory, creating names like "folder-folder-folder-folder-file.txt".
Just use command like Im giving the first time in this format...

"C:\Program Files\Bulk Rename Utility\BRCUnicode64\BRC64.exe" /dir:"C:\FolderPath" /recursive /pattern:*.txt /appendfolder:"P: - :1"
Then experiment on the command line to get your " - " separators correct, then adding /execute for the batch.
Luuk
 
Posts: 132
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to append folder name using a .bat file

Postby killerfrog423 » Thu Feb 11, 2021 4:49 am

without the "FOR" it does nothing, like I said bug, I'll try to get the spaces to work.
killerfrog423
 
Posts: 5
Joined: Mon Jan 04, 2021 2:27 pm

Re: How to append folder name using a .bat file

Postby Luuk » Thu Feb 11, 2021 5:36 am

Im just testing and it worked perfectly. My command....
BRC64.exe /dir:"C:\MyFolderPath" /recursive /pattern:*.txt /appendfolder:"P: - :1"

My results...
Processing Folder C:\MyFolderPath\Folder1\
Filename 01.txt would be renamed to Folder1 - 01.txt
Filename 02.txt would be renamed to Folder1 - 02.txt
Filename 03.txt would be renamed to Folder1 - 03.txt

Processing Folder C:\MyFolderPath\Folder2\
Filename 01.txt would be renamed to Folder2 - 01.txt
Filename 02.txt would be renamed to Folder2 - 02.txt
Filename 03.txt would be renamed to Folder2 - 03.txt

Processing Folder C:\MyFolderPath\Folder99\
Filename 01.txt would be renamed to Folder99 - 01.txt
Filename 02.txt would be renamed to Folder99 - 02.txt
Filename 03.txt would be renamed to Folder99 - 03.txt

So the only 'bugs' is letting FOR restart brc64.exe for every .txt, and not using quotes around the spaces.
It really is just that easy, Im no reason to lie about it.
Luuk
 
Posts: 132
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to append folder name using a .bat file

Postby killerfrog423 » Thu Feb 11, 2021 9:15 pm

Yes that way works, but I am using a .bat file inside the folder that changes location. I am copying this .bat file to multiple locations and running it. At this point we are stuck using the GUI. Would have been nice to automate some of the tasks.
killerfrog423
 
Posts: 5
Joined: Mon Jan 04, 2021 2:27 pm

Re: How to append folder name using a .bat file

Postby Luuk » Thu Feb 11, 2021 10:23 pm

The "/dir:FolderPath" only chooses location, not how the files getting renamed.
If to never know the folder paths, and prefer copying batchs to folders, then just destroy "/dir:FolderPath".
Then, whenever you click the batch, the only difference is that it conducts the folder where you copied it to.

Also, one batch can do "multiple locations" like...
brc64 /dir:"Location1" /recursive ...
brc64 /dir:"Location2" /recursive ...
You can make the locations either a drive, or some folder path, and they conduct recursively.

If its me, Im make a registry setting, so when you right click a folder, just choose "AppendFolder".
Then the batch only conducts that folder(s), its to be much better than copying batches.
Luuk
 
Posts: 132
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to append folder name using a .bat file

Postby Luuk » Fri Feb 12, 2021 6:54 am

If you like to experiment, I make this batch as example...
Code: Select all
@echo off
Reg Query "HKCU\Software\Classes\Directory\shell\PrefixTextFiles" >nul 2>nul && set "ACT=Uninstall" || set "ACT=Install"
echo %ACT%ing "PrefixTextFiles" Folder Context Menu
echo This to let you right click any folder, so the .txt files inside get a prefix like "FolderName - "
echo Its smart to see if correct FolderName is already in front, so instead going to next .txt file
echo.
If /i [%ACT%] == [Install] (
REG ADD "HKCU\Software\Classes\Directory\shell\PrefixTextFiles\command" /ve /d "C:\Program Files\Bulk Rename Utility\BRCUnicode64\BRC64.exe /recursive /pattern:*.txt /dir:\"%%1\" /appendfolder:\"P: - :1\" /regexp:\"^^^(.+?^)^( - ^)^(\1[ -]+^)+^(.*^):\1\2\4\" /execute" /f) > nul
If /i [%ACT%] == [Uninstall] (REG DELETE "HKCU\Software\Classes\Directory\shell\PrefixTextFiles" /f) > nul
echo %ACT%ed Context Menu (Right click folder for PrefixTextFiles),  Press any key to exit
pause>nul

Save it as batch, then clicking it will make the setting for you, so then right clicking any folder presents "PrefixTextFiles".
It doesnt create another batch, but only holds the brc64 command inside the registry, but this part can be easy to change
Also, I added /regexp in case the FOR experiments created way too many files like "Folder1 - Folder1----Folder1-file.txt"

So the command first prefixes "FolderName - " then /regexp looks for more of that "FolderName" to remove them like...
Folder1 - Folder1-Folder1---Folder1--Folder1-001.txt ===> Folder1 - 001.txt
Folder1 - Folder1-Folder1 - Folder1--Folder1-002.txt ===> Folder1 - 002.txt
Folder1 - Folder1--- --Folder1--- -----Folder1-003.txt ===> Folder1 - 003.txt

It only depends on brc64.exe path being like you said... C:\Program Files\Bulk Rename Utility\BRCUnicode64\BRC64.exe
If you decide not to like the right click option anymore, then just click the batch again, and it destroys the setting.
So each time clicking it, will either invent or destroy the right click option... "PrefixTextFiles"
Luuk
 
Posts: 132
Joined: Fri Feb 21, 2020 10:58 pm

Re: How to append folder name using a .bat file

Postby killerfrog423 » Mon Feb 15, 2021 2:02 pm

This works perfectly! Thank you!
killerfrog423
 
Posts: 5
Joined: Mon Jan 04, 2021 2:27 pm


Return to How-To