im pretty new ro batch programming and i just can not get it done.
I already spend hours and this so i really hope some of you guys are able to help me out!
I have many .txt files in a local folder named like e.g: 0200_some_other_stuff_0x201548_5555.txt
Now i would like to zip this files.
Heres the big problem i can not solve:
I want the name of the zipped folder to depend on the zipped file.
If the file name is: 0200_some_other_stuff_0x201548_5555.txt
i would like the zipped folder to be named: 0200_NEW_NAME_0x201548_5555.zip
So basically i would like to keep the numbers from the old name string and only replace the middle part with smth. new.
Is this possible?
How do i do the string manipulation in the loop?
Do i need to set the file name into a variable and then manipulate it to extract the string part i want?
How would i do that?
This is what i got:
Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
@echo off
FOR /r %%A IN (*.txt) DO (
M:\7-Zip\7z.exe a "%%~nA.zip" "%%~nA.txt"
pause
)
Also this does zip only one single file and not all .txt files that are in the folder.
Do you know what im doing wrong?
I would really appreciate some help guys, so many thanks in advance!
EDIT: removed the recursive parameter in my example code.