Jump to content
Ketarin forum

Using variable names in Commands


TheWacoKid
 Share

Recommended Posts

I’m new to Ketarin and I’m trying to set up a system that downloads the newest version of software and keeps an archive of older versions. So far this is what I have the program doing.

 

1)      I copy any existing files from the “live” folder to the archive. I then empty that folder.

xcopy {root}\Users\Admin\Desktop\Test_Updater\{appname} {root}\Users\Admin\Desktop\Test_Updater\Archived_Versions\{appname} /C /Y
cd /d {root}\Users\Admin\Desktop\Test_Updater\{appname}
del *.exe

2)      Ketarin downloads the newest version to the “live” folder.

 

3)      I use 7zip to archive the file that I moved in step one, and delete the file.

cd /d {root}\Users\Admin\Desktop\Test_Updater\Archived_Versions\{appname}
for %%f in (*.exe) do (echo %%~nf
C:\Users\Admin\Downloads\7za920\7za.exe a %%~nf.7z *exe -aoa %%f)
del *.exe

The problem I’m having is with the archive’s name. I’m using a variable, that works in cmd prompt, to take the .exe’s name and apply it to the .7z file. Ketarin doesn’t act like cmd in this instance. Instead of taking the variable, it’s saving the file as %%~nf.7z.

 

Here is the version from my .bat file that works without issue.

cd /d "C:\Users\Admin\Desktop\Test_Updater\Archived_Versions\WinRAR x64"
for %%f in (*.exe) do (echo %%~nf
C:\Users\Admin\Downloads\7za920\7za.exe a %%~nf.7z *exe -aoa %%f)
 
Any thoughts on what I’m doing wrong?
Link to comment
Share on other sites

That's how i use it to archive some files.

globalvarsqxy75.png

To avoid redundant usage of pathes, create global variables. For 7zip copy the 7z.dll and 7z.exe to your Ketarin folder, create a global variable called 7z and point it to your 7z.exe
Create a second global variable called archived and point it to {root}\archived or chose any other path.

 

My batch code:

IF NOT EXIST "{archived}\{appname}" (
  MD "{archived}\{appname}"
)

"{7z}" u -t7z -mx9 "{file:directory}\{yyyy}{MM}{dd}.7z" "{file}"

MOVE /Y "{file:directory}\*.7z" "{archived}\{appname}"

And I use the time stamp ({yyyy}{MM}{dd}) for naming my archives...

 

To get back to your problem. Have you checked the log file (CTRL+L) for errors?

Link to comment
Share on other sites

Batch scripts are functionally processed as individual lines, not as actual scripts. You'll get better results if you compound the lines with && as so:

cd /d {root}\Users\Admin\Desktop\Test_Updater\Archived_Versions\{appname} && for %%f in (*.exe) do (echo %%~nf  &&  C:\Users\Admin\Downloads\7za920\7za.exe a %%~nf.7z *exe -aoa %%f) && del *.exe
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.