0

I have a couple of folders each containing up to 100 pdf files more or less. For each folder I want to batch rename the files so that they will start with the Hebrew letter "ת" and then will have a sequential number. However, I don't want to start the numbering from 1. For example:

pdfa will be ת20
pdfb will be ת21
pdfc will be ת22
and so on...

I tried looking at previous questions and coping the codes that were suggested there with the appropriate changes (like this one and this one but when running the codes on powershell it kept saying that either something in the command is missing or that something in the command is invalid (if needed, I can supply screenshots).

Codes I've tried:

@echo off
setlocal ENABLEDELAYEDEXPANSION
set/a fileNum = 1
for %%f in (*.mp4) do (
  ren %%~nf%%~xf !fileNum!%%~xf
  set/a fileNum += 1
)

The powershell has said that @echo off is an Unexpected token, so I tried removing that line. It then said The term 'setlocal' is not recognized as the name of a cmdlet, function, script file, or operatble program. After that notice it continued with set/a and said the same thing, and finally it showed the rest of the code and said it is missing and opening and closing. I then tried running ls -v | cat -n | while read n f; do mv -n "$f" "$n.pdf"; done. I got the error Missing statement body in do loop.

It is important to notice that I have permission to reach these files only via my work computer which means that I'm not the admin and I cannot download new software.

Is there a way to do so?

Thanks in advance.

Boof
  • 1
  • 2
  • If you require us to assist you to fix a problem with your code, we require at least a [mcve] of that code. – Compo May 08 '23 at 20:06
  • I apologize. I thought that sending the links to the posts from which I have copied the codes was enough. I've now edited the post to add code examples and the error messages I've gotten in return. @Compo – Boof May 09 '23 at 06:01

1 Answers1

0

The file is not in powershell language it is written for windows command console running as a bat or cmd file here is an example of it working at command prompt after adding in CHCP changes for Hebrew, but note in my LTR explorer they show a different name order compared to the command file sequence !

I am sticking with mp4 as your code sample shows that not PDF but simply edit the batch file there from mp4 to pdf!

enter image description here

>REM lets add some files
>for /l %c in (1,1,5) do @echo file %c>file%c.mp4
>dir
 Volume in drive C is Windows
 Volume Serial Number is 942F-936A
 Directory of C:\test

2023-05-09  14:17    <DIR>          .
2023-05-09  14:17    <DIR>          ..
2023-05-09  14:18                 8 file1.mp4
2023-05-09  14:18                 8 file2.mp4
2023-05-09  14:18                 8 file3.mp4
2023-05-09  14:18                 8 file4.mp4
2023-05-09  14:18                 8 file5.mp4

>REM lets rename using the batch file
>..\renumb
>echo off
Active code page: 65001
Active code page: 1255
>dir
 Volume in drive C is Windows
 Volume Serial Number is 942F-936A

 Directory of C:\test

2023-05-09  14:19    <DIR>          .
2023-05-09  14:19    <DIR>          ..
2023-05-09  14:18                 8 20ת.mp4
2023-05-09  14:18                 9 21ת.mp4
2023-05-09  14:18                 8 22ת.mp4
2023-05-09  14:18                 8 23ת.mp4
2023-05-09  14:18                 8 24ת.mp4
              10 File(s)             81 bytes
               2 Dir(s)  756,414,377,984 bytes free
>

The mod needed is troublesome adding RTL characters so you may need to edit very carefully and alter the chcp values in a native Hebrew Windows MS Notepad. I suggest you run chcp on its own at cmd window to check your own current default, as I had to guess for English testing.

renumb.bat

@echo off
chcp 65001
setlocal ENABLEDELAYEDEXPANSION
set/a fileNum = 20
for %%f in (*.mp4) do (
  ren %%~nf%%~xf !fileNum!ת%%~xf
  set/a fileNum += 1
)
chcp 1255

K J
  • 8,045
  • 3
  • 14
  • 36