I've seen questions that I think are similar (but which I cannot make work for me), but I am very new to batch files so I don't understand what needs to be different to make it work. I have a folder /source/
with some files, say:
- red.txt
- orange.txt
- yellow.txt
- green.txt
- blue.txt
- purple.txt
I need to make a batch file that will run 7zip on all of them automatically to create zipped version of them. I found some resources which I thought would help but after a few hours of frustration, I think I'm forced to confront the fact that I simply don't know enough about Batch files to understand why it isn't working?
My effort was:
:: Changes directory to this file's directory
cd %~dp0
:: Location of source data
set dirSource="C:\Source\"
:: Target location of zipped data
set dirTarget="C:\Target\"
cd %dirSource%
for %f in (%dirSource%*.txt) do
(
7z.exe a "%dirTarget%\%%~NF.zip" "%dirSource%\%%~NXF"
:: based on related searches on the internet
:: but I can't find an explanation of _why_ this is supposed to work, which makes it hard to know why it isn't
:: ie, what does "a" do? What is ~NF vs ~NXF? etc
)
Lastly - I have been utterly unable to find a good comprehensive guide to batch files because of all the weird character modifiers. Since I don't expect to pick it all up in this question, if anyone has a good guide where I can look up what some of these seemingly random character combinations mean I would be forever grateful.