batch file gpg command - batch-file

I want to encrypt files using GnuPG. I have written a .bat file to do that. The contents of the bat file is like
gpg --trust-model always --recipient aaa#yyy.com --encrypt File_name
when the file i want to encrypt is on my local machine this works fine.
but what i want is to encrypt a file that is on a shared path (without copying to my local machine). when i give the File_name as \\shared_path\File_name i get gpg: file not found error.
Any sort of help is appreciated.

Perhaps gpg cannot handle UNC paths. Try using PUSHD to temporarily change your directory to the UNC path
pushd \\shared_path
gpg ...
popd

Related

How to create a batch file that will zip few different files in one .zip file

I want to create a batch/shell script for windows and mac that will take few different files with different types and will compress it to a .zip file.
I already saw a few questions and answers about it, but all of them either compress all the files in the folder or compress them individually.
Example (look at attached image):
I have a folder that contains 1.txt, 2.xml, a sub directory.
And I want to turn all of them into a .zip file.
If possible to get a solution both for windows and Mac.
On Windows there is the file 7zip.chm in directory %ProgramFiles%\7-Zip which is the help file of 7-Zip. Double click on this file to open the help.
On Contents tab there is the list item Command Line Version with the help pages:
Syntax ... Command Line Syntax
Commands ... Command Line Commands
Switches ... Command Line Switches
The target is to compress everything in folder test into a ZIP file with name of the folder as file name.
This could be done for example with the command line:
"%ProgramFiles%\7-Zip\7z.exe" a -bd -mx=9 -r -y -- test.zip "C:\Path to Directory\test\*"
This command line adds (a) everything in directory C:\Path to Directory\test recursive (-r) to a ZIP file with name test.zip in current working directory without progress indicator (-bd) using best ZIP compression (-mx=9) with assuming Yes on all queries (-y).
In other words the file test.zip in current directory contains after execution the subdirectory main with everything inside and the files 1.txt and 2.xml.

Retrieve EXE file version from file in current directory

I have a batch script that is in version control and can be checked out into any directory, but it should only work on the current directory:
#echo off
zip -9 Setup.zip Setup.exe SetupGuide.pdf
Now the batch file should retrieve from Setup.exe the version, check a network drive whether the file Setup.<versionstring>.zip exists and throw an error if it does, or else copy the Setup.zip to the network drive as Setup.<versionstring>.zip.
I found that I can get the version string using WMIC, but it seems to only take the full path name and furthermore needs double backslashes. How can I tell WMIC that I want a file from the current directory?
T:\Installer\SetupFiles>wmic datafile where name='.\\Setup.exe' get version
Keine Instanzen verfügbar.
I think you need to provide the full path to the executable:
wmic datafile where name="T:\\Installer\\SetupFiles\\Setup.exe" get version

How to mention C:\Program Files in batchfile

I need to invoke an exe file in C:\Program Files directory from a batch file.How can we mention the directory name "Program Files" in batch file.I am getting error like C:\Program not found.
I believe that % or ~ needs to be added in between but couldn't get it.Kindly assist.
Surround the script call with "", generally it's good practices to do so with filepath.
"C:\Program Files"
Although for this particular name you probably should use environment variable like this :
"%ProgramFiles%\batch.cmd"
or for 32 bits program on 64 bit windows :
"%ProgramFiles(x86)%\batch.cmd"
On my pc I need to do the following:
#echo off
start C:\"Program Files (x86)\VirtualDJ\virtualdj_pro.exe"
start C:\toolbetech\TBETECH\"Your Toolbar.exe"
exit
Now that bash is out for windows 10, if you want to access program files from bash, you can do it like so: cd /mnt/c/Program\ Files.
I use in my batch files - c:\progra~2\ instead of C:\Program Files (x86)\ and it works.
I had a similar issue as you, although I was trying to use start to open Chrome and using the file path. I used only start chrome.exe and it opened just fine. You may want to try to do the same with exe file. Using the file path may be unnecessary.
Here are some examples (using the file name you gave in a comment on another answer):
Instead of C:\Program^ Files\temp.exe you can try temp.exe.
Instead of start C:\Program^ Files\temp.exe you can try start
temp.exe
use this as somethink
"C:/Program Files (x86)/Nox/bin/nox_adb" install -r app.apk
where
"path_to_executable" commands_argument
Interestingly with variables ,this worked for me ...
SET "VESTADIR=\\%TARGET%\C$\"Program Files (x86)"\Cassidian\VESTA"
While createting the bat file, you can easly avoid the space. If you want to mentioned "program files "folder in batch file.
Do following steps:
1. Type c: then press enter
2. cd program files
3. cd "choose your own folder name"
then continue as you wish.
This way you can create batch file and you can mention program files folder.

ftp batch file log data to txt

me again :P
I have some problems with some bat file, that bat file , connects to and ftp and download all files from a remote folder, then delete it, but my problem/question is: i need a txt(log) of every file before download it from the remote server, here is my file
bat file:
ftp -i -s:ftpfile.txt site.com
txt file
user-name
user-pass
lcd c:\localfolder\some\folder
cd remotefolder-name
mget .
mdelete \\remotefolder-name\ .
quit
If i use the >>mylog.txt on this line:
ftp -i -s:ftpfile.txt site.com>>mylog.txt
I get some extra data that i dont want to. I just need the file names before download it, something like this:
log.txt
file001x.xml
filedfx.xml
file023x.xml
filed33x.xml
Ps:sorry for my english ;)
You may redirect ls output to local file. Syntax is: ls pattern local_file. An example would be: ls * ftplist.txt or ls . ftplist.txt. Both will produce a file ftplist.txt (in local current directory if you do not specify path) with a list of files (and possibly subdirs) in current directory on remote server (in slightly different formats)

Make a batch that detects its own filepath

I need to make a batch file that detects what drive and directory it is in. When I run the the file normally, it is in the correct directory/drive already. But when it is run as admin, it starts in system32. Is there a command that goes to the directory or drive the batch came from?
You could use
Pushd "%~dp0"
This changes the current directory to the path of the batch file.
Quoting the argument makes it safe against special characters in the pathname like "C:\Documents & Settings"
well a workaround is to use \ before the path to give absolute path.
So, if you need to run a file c:\temp\xyz.exe and even if you are in directory c:\winodws\system32 still when you do cd \temp\xyz.exe still the file will run properly

Resources