loading

What is wrong in my batch file?

@echo off

title Camo

echo what is the location of the folder that has the files (e.g C:\x)

set /p file=C:\x

echo what is the name of the file that you are trying to hide in

set /p namefile=picture

echo what is the name of the 7z file that you created (including format)

set /p zip=File2.7z

echo what will be the name of the new picture that will be created containing the files

set /p namehider=newpicture

echo what is the picture's format?

set /p format=PNG

cd %file%

copy /b %namefile%.%format% + %zip% %namehider%.%format%

I am attempting to automate a process that I do manually but can't seem to get the desired result. First i must have 7zip compress a couple files from a specific folder, which, I haven't attempted to write commands for yet (taking suggestions). Next the below is intended to run in CMD using the created zip file and a picture like so

cd\

enter

cd x

enter

copy /b Picture.png + x.7z NEWPICTURE.png

The product should be deposited back into C:\X

sort by: active | newest | oldest
mh76dk2 years ago

You can copy from and to a directory and avoid all the CDing around:

copy /b C:\x\Picture.png + C:\x\x.7z C:\x\NEWPICTURE.png

or in your batch file:

copy /b %file%\%namefile%.%format% + %file%\%zip% %file%\%namehider%.%format%

g-one mh76dk2 years ago

I'm suggesting to always use double quotes to enclose the pathes. If having spaces somewhere in the folder or file names it wouldn't work without (and is harmless otherwise).

copy /b "%file%\%namefile%.%format%" + "%file%\%zip%" "%file%\%namehider%.%Format%"

mh76dk g-one2 years ago
"Very true." :)

I only wanted to point out that you can use full/relative paths on the file(s) in commands. (I even managed not to whine about calling the 'path' variable 'file' - until now. :-)

g-one mh76dk2 years ago

Usually I don't complain about confusing variable names like "file" as long as they never(!) overwrite the "path" variable. Let them call it "prettyflower" or "uglyfrog". But "path" is predefined and contains the lookup list of pathes for system tools. As soon as you overwrite its content the command tools (FIND, MORE, XCOPY, etc.) can't be found anymore ;-)

mh76dk g-one2 years ago

Is %path% and %PATH% the same on windows? I havent used windows for 10+ years and even then it was a rare thing. (Not that it ended up being an issue, he picked %folder%, which for all i know could be reserved too :-)

And anyways, what is the problem with no %PATH%? just means you have to type out the full path to your command.... kids these days ;-)


g-one mh76dk2 years ago

Names of environment variables are not case sensitive on Windows.

%PATH% == %path% == %Path% == %pAtH% etc.

And you are right. Without or with an invalid path variable you have to use the full path to the system tool. Fortunately it will not cause a persistent problem because the scope for the altered variable is the running process (and its child processes that inherit the environment) only.

mh76dk g-one2 years ago

I should probably have picked something else than 'path' then. As my major complaint was calling something which is not a file a file, not so much which alternative to pick. Just karma that I make such a mistake when correcting someone I suppose :-)

I will keep the case-insensitivity in mind for the future, mean little gotcha.

Dauntless (author) 2 years ago

I want to thank everyone for their input, I got that part of the batch to function, i'm still learning so it helps to get a more experienced eye. I am still in need of the other half which is to have 7zip, or what ever zip i designate, auto run and create a zipped file. This should be fesable correct?

Vyger2 years ago

If you are using windows 7 (looks like it) you need to run the CMD window as an administrator for certain processess. I made a very simple batch file to change a directory name to disable a program from runing and another to change it back. Named them lock and unlock. They work great as long as you right click them and then say run as administrator. That could be part of your problem.

Dauntless (author) 2 years ago

Here is the batch file as I have it.

@echo off

title Sub-Visual Binary Encrytion

echo what is the location of the folder that has the files (e.g C:\x)

set /p file=C:\Enigma

echo what is the name of the file that you are trying to hide in

set /p namefile=Liberty

echo what is the name of the 7z file that you created (including format)

set /p zip=Freedom.7z

echo what will be the name of the new picture that will be created containing the files

set /p namehider=1776

echo what is the picture's format?

set /p format=Png

copy /b %file%\%namefile%.%format% + %file%\%zip% %file%\%namehider%.%format%

I cannot see how that would cause the errors/behavior you posted below. Try quoting the copy arguments (as per g-ones suggestion). Otherwise I really have no idea. :-(

(Please use the reply-button in the comment you reply to, it was pure chance i saw this as it is not nested under my answer)

Dauntless (author)  mh76dk2 years ago

ok disregard that last comment, it was a user error. i think i may have found something, when runing it with "@echo off" removed so the commands display i see the path its using is:

C:\users\dustin\desktop>set /p folder=C:\Enigma

could that be the issue?

That looks like you are running the command 'set...' in the desktop folder. which i would think should be ok (but see last paragraph), as long as all the filenames you work with are given a full path. (i hope you renamed all the %file% to %folder% too?).

I am a bit worried that since im not a 'windows guy' I am missing something obvious. But a few ideas:

The best way to test is to write the entire command in the batchfile just like you would on the commandline. then start replacing parts with the variables you set only after you have veryfied that the command will work. That way you can rule out one problem at a time.

Another usefull approach to see what all your variables end up looking like is to echo them instead of running the copy command: echo "folder is %folder%"

The fact that you run the batchfile in the desktop folder and the kinda files the errors you got was from (.lnk), i have a suspicion that it somehow starts working on the files in the current directory, but if all your variables are set/used correctly that should not happen. I suggest you do not actually copy any files before you are sure it works on the right ones, you can accidently copy garbage over an important file.

Dauntless (author)  mh76dk2 years ago

I just tried to run copy /b C:\x\Liberty.png + C:\x\Freedom.7z C:\x\1776.png but received an error that "the system cannot find the path specified"

Dauntless (author) 2 years ago

I attempted your suggestions and this is what I got

bat.png

Unfortunately I dont know CMD very well (I'm mostly on Linux or similiar) so it is very hard to see what goes wrong here. And without the batchfile source I can't even make an unqualified guestimate.

iceng2 years ago

try

CD..