JREN.BAT v2.8 - Rename files/folders using regular expressions

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
dostipsQuestion
Posts: 4
Joined: 13 May 2020 18:01

Re: JREN.BAT v2.8 - Rename files/folders using regular expressions

#61 Post by dostipsQuestion » 15 May 2020 09:47

dbenham wrote:
14 May 2020 09:04
Question 1

I'm not exactly sure what you are trying to do.

If you want only the size of a single folder,
like "D:\portable", then specify the root path with /P and
specify the specific folder with /FM

Code: Select all

call jren "^" "size()+'  '" /d /j /list /p "d:\" /fm "portable"
Dave Benham
.
Hello Dave Benham,
Thank You for the code below:

Code: Select all

call jren "^" "size()+'  '" /d /j /list /p "d:\" /fm "portable"
Desired output is achieved:
3596879 portable
Thank You


Question:
How to use above code with variables?

Code: Select all

call jren "^" "size()+'  '" /d /j /list /p "%~d0" /fm "%~p0" > "FolderList1.txt"
%~d0 = d:
%~p0 = \portable\

The problem is the \

Said differently:
"portable" = Directory name with no \ \ = works in above code.
"\portable\" = %~p0 = does not work in above code.


Help.
Please clarify how above variables in batch can be done.

--

dbenham
Expert
Posts: 2369
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: JREN.BAT v2.8 - Rename files/folders using regular expressions

#62 Post by dbenham » 15 May 2020 15:18

The /FM must be the name of the folder or file you want, and the /P must be the full path leading up to that file/folder.

Code: Select all

for %%F in ("%~dp0.") do call jren "^" "size()+'  '" /d /j /list /p "%%~dpF" /fm "%%~nxF" > "FolderList1.txt"
"%~dp0." expands to "D:\portable\.", which is logically equivalent to "D:\portable"

So in the FOR loop, "%%~dpF" yields "D:\" and "%%~nxF" yields "portable".

Note that a folder name could include an extension, which is the reason I use %%~nxF instead of %%~nF.

Similarly I use %%~dpF instead of %%~dF just in case your batch script is not in a folder that hangs of the root.

dostipsQuestion
Posts: 4
Joined: 13 May 2020 18:01

Re: JREN.BAT v2.8 - Rename files/folders using regular expressions

#63 Post by dostipsQuestion » 16 May 2020 21:23

Hello Dave Benham,
Thank You for the code in above post.

Below are slight changes to your code.
These changes might add clarity for others:

Code: Select all

for %%F in ("%~dp0.") do call D:\Batches\JREN\JREN.BAT "^" "size('               ')+'  bytes in       '" /d /j /list /p "%%~dpF" /fm "%%~nxF" > "R:\FolderList1.txt"
Above code of JREN.bat version 2.8 gives desired output as:
______227595130 bytes in FireFox


The above _ is added to align numbers in this post.
Actually, JREN.bat automatically aligns by padding with blank spaces.


Regarding counting, I am unsure as to what else JREN.bat can do.
Maybe JREN.bat can also do more than byte counting as per above code.
So I will ask.
I rather use JREN.bat versus other commands.

What code would tell JREN.bat version 2.8 to:
1. count Files?
2. count Folders?

Looking for output:
______227595130 bytes in FireFox
____________387 Files
_____________86 Folders

If JREN.bat cannot count files and folders as shown above,
then counting can be made in batch with:
dir /a:-d /s /b | find /c ":\" > "R:\FolderList1.txt"
dir /a:d /s /b | find /c ":\" > "R:\FolderList1.txt"


And, what code would tell JREN.bat version 2.8 to:
3. List all Files?

Looking for output:
S:\FireFox\App
S:\FireFox\Data
S:\FireFox\help.html
S:\FireFox\FirefoxPortable.exe
Etc.

If JREN.bat cannot output above files then I can use a batch with:
dir /s /b /ON > "R:\FolderList1.txt"



And, what code would tell JREN.bat version 2.8 to:
4. Date & Time stamp? Ideal stamp:
Ended : Sat 16 May 2020 at 11:55:14
If JREN.bat cannot stamp as above then this is close:
"C:\WINDOWS\system32\ROBOCOPY.EXE" /L * \ \ | find /i "Ended" >> "R:\FolderList1.txt"


And, what code would tell JREN.bat version 2.8 to:
5. Give credit to you in TEXT files? Meaning:
JREN.BAT version 2.8 by Dave Benham
Put above text to a file.

Because this does work at windows command line:
D:\Batches\JREN\JREN.BAT /?VERSION
But above command did not work inside a batch.

and
your web site for JREN.BAT would be good for a text file.
http://_


6. Curious, what is maximum JREN.BAT byte count?
For sure JREN.BAT can count to 255 GB, example:
___255000111222 bytes


Byte count background:
https://superuser.com/questions/222249/ ... 267#222267
As designed, the maximum NTFS file size is
16 EB (16 × 1024^6 bytes) minus 1 KB (1024 bytes) or
18,446,744,073,709,550,592 bytes.

As implemented, the maximum NTFS file size is
16 TB (16 × 1024^4 bytes) minus 64 KB (64 × 1024 bytes) or
17,592,185,978,880 bytes.

Said differently, maximum NTFS file size is:
18446744073709550592 bytes by design _______ > 18 quintillion
______17592185978880 bytes by implementation > 17 trillion

Maximum volume size
Implementation:
256 terabytes minus 64 KB ( 232 clusters minus 1 cluster)
https://docs.microsoft.com/en-us/previo ... dfrom=MSDN



--

dbenham
Expert
Posts: 2369
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: JREN.BAT v2.8 - Rename files/folders using regular expressions

#64 Post by dbenham » 18 May 2020 07:30

In general, the built in help (JREN /?) does a good job describing the features of JREN. It is up to you to figure out how to use those features. Plus there are examples throughout this thread. I hope you take the time to scan all the posts.
dostipsQuestion wrote:
16 May 2020 21:23
What code would tell JREN.bat version 2.8 to:
1. count Files?
2. count Folders?

Looking for output:
______227595130 bytes in FireFox
____________387 Files
_____________86 Folders
JREN does not have any feature to provide a summary at the end of all processing. That might be an interesting feature to add, though I'm not particularly inclined to invest in much more development with this project. It is significantly behind in its Unicode capabilities compared to JREPL.BAT - regular expression find/replace utility. And the date/time formatting and computation capabilities lag compared to what is available in jTimeStamp.bat. I probably want to address that before I add any new features, but there just doesn't seem to be that much interest in this utility. By far my most widely used utility is JREPL.BAT. You should check that out if you haven't seen it already.
dostipsQuestion wrote:
16 May 2020 21:23
And, what code would tell JREN.bat version 2.8 to:
3. List all Files?

Looking for output:
S:\FireFox\App
S:\FireFox\Data
S:\FireFox\help.html
S:\FireFox\FirefoxPortable.exe
Etc.
Not sure exactly what you are looking for. JREN can process (list) files or folders, but not both at the same time. The /S option allows recursion of subdirectories. So the following would list all files within the folder tree rooted at the current directory:

Code: Select all

jren "^" "path()" /list /s /j
JREN processes system and hidden files the same as any other. Use the many other options to specify the root folder, and filter paths and files as needed.
dostipsQuestion wrote:
16 May 2020 21:23
And, what code would tell JREN.bat version 2.8 to:
4. Date & Time stamp? Ideal stamp:
Ended : Sat 16 May 2020 at 11:55:14
You need to investigate the /TS option. The following JScript expression using the FileSystemObject will yield your desired format if your computer's date format can be parsed by JScript

Code: Select all

ts({ dt:'fsoCreated', fmt:'Ended : {wkd} {d} {month} {yyyy} at {hh}:{nn}:{ss}' })
If the date cannot be parsed, then you will need the much slower WMI variant:

Code: Select all

ts({ dt:'created', fmt:'Ended : {wkd} {d} {month} {yyyy} at {hh}:{nn}:{ss}' })
dostipsQuestion wrote:
16 May 2020 21:23
And, what code would tell JREN.bat version 2.8 to:
5. Give credit to you in TEXT files? Meaning:
JREN.BAT version 2.8 by Dave Benham
Put above text to a file.

Because this does work at windows command line:
D:\Batches\JREN\JREN.BAT /?VERSION
But above command did not work inside a batch.
JREN.BAT is a batch script, so you must use CALL JREN within your own script, else it won't return to your script.
dostipsQuestion wrote:
16 May 2020 21:23
your web site for JREN.BAT would be good for a text file.
http://_
I treat this DosTips thread as the primary source for JREN. https://www.dostips.com/forum/viewtopic.php?f=3&t=6081

The closest thing I have to a personal website is my StackOverflow profile: https://stackoverflow.com/users/1012053 ... ab=profile

And for music I have my YouTube channel - www.youtube.com/c/DaveBenhamMusic
and SoundCloud channel - www.soundcloud.com/dave-benham

dostipsQuestion wrote:
16 May 2020 21:23
6. Curious, what is maximum JREN.BAT byte count?
For sure JREN.BAT can count to 255 GB, example:
___255000111222 bytes
I don't know for sure. I'm relying on built in Microsoft routines to get the files sizes. My guess is that it cannot exceed the maximum JScript integer size of (2^53)-1 = 9,007,199,254,740,991. And then within that limit I imagine it is dependent on the underlying file system.


Dave Benham

dostipsQuestion
Posts: 4
Joined: 13 May 2020 18:01

Re: JREN.BAT v2.8 - Rename files/folders using regular expressions

#65 Post by dostipsQuestion » 20 May 2020 07:32

.
With code below, JREN.BAT works great giving output:

____87111222333 bytes in Archive

Note the _ means padded blank spaces.


Question:
What is an easy way to use above
1 line output and get this
4 line output?

_______________ TB (Tera Bytes)
____87_________ GB (Giga Bytes)
____87111______ MB (Mega Bytes)
____87111222___ KB (Kilo Bytes)
____87111222333 bytes in Archive


Said differently, replace numbers with blank spaces.
Not doing math of divide by 1024.
Just truncate.
Just replace numbers with blank spaces.


Can above 5 line output be done inside JREN?

If so, please make a suggestion as to how and
point me to line number inside JREN.bat

If not, then what suggested Text Tool can manipulate the
1 line output?
____87111222333 bytes in Archive


Code for JREN.bat

Code: Select all

for %%F in ("%~dp0.") do call D:\Batches\JREN\JREN.BAT "^" "size('               ')+'  bytes in       '" /d /j /list /p "%%~dpF" /fm "%%~nxF" > "d:\FolderList1.txt"

--

dbenham
Expert
Posts: 2369
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: JREN.BAT v2.8 - Rename files/folders using regular expressions

#66 Post by dbenham » 20 May 2020 08:55

I'm' going to leave that coding exercise to you. The entire JScript language is at your disposal. You can include newlines in your output with the correct JScript code.

Post Reply