Batch Questions

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
john924xps
Posts: 65
Joined: 08 Jun 2012 07:48

Batch Questions

#1 Post by john924xps » 31 Oct 2012 21:53

I'm attempting to create a custom command w/ a parameter using cmd as base.

Code: Select all

set command=command [attrib] /s
call :check %command%

:check
if %3==...


But what if they don't use the additional "attrib"? Then /s would be %2

And how do I disallow the ability of turning echo back on, in order to prevent code leaks? It is a custom batch program, so they are allowed to run any command they want...


And this another program that I am trying to create, but am stuck on... a backup program that copies the content of the folder ".john924xps" into a folder named backup. And this is the code I have so far

Code: Select all

@echo off
title Backup
color 0a
if not exist "Backup" md "Backup"
cd .john924xps
for /f %%G in ('dir /b') do (xcopy "%%G" "%userprofile%\Desktop\Backup" /h /e /f /t /i)
pause


And I'm not exactly sure if in the code above I'm supposed to use /f or just a plain for loop.
FOR - Loop through a set of files in one folder
FOR /F - Loop through the output of a command
both seem like they can fit my expectations

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch Questions

#2 Post by foxidrive » 31 Oct 2012 21:59

john924xps wrote:And this another program that I am trying to create, but am stuck on... a backup program that copies the content of the folder ".john924xps" into a folder named backup. And this is the code I have so far

Code: Select all

@echo off
title Backup
color 0a
if not exist "Backup" md "Backup"
cd .john924xps
for /f %%G in ('dir /b') do (xcopy "%%G" "%userprofile%\Desktop\Backup" /h /e /f /t /i)
pause



Maybe this will do:

Code: Select all

xcopy ""%userprofile%\Desktop\.john924xps\*.*" "%userprofile%\Desktop\Backup\" /s/h/e/k/f/c


A fellow once commented that those xcopy switches are pretty useful and easy to remember in the phrase "SHE likes KFC"


I don't follow your first question.

john924xps
Posts: 65
Joined: 08 Jun 2012 07:48

Re: Batch Questions

#3 Post by john924xps » 01 Nov 2012 06:13

Okay... this is what I mean in the first question. I am creating a custom command prompt, that acts like a regular command prompt, except only that there are a couple of my own added commands. Example the TEST command, it is used to see what a certain command does. This is the syntax:
test [command] [/f]

I want to check whether or not the parameter is being used. How would I do that?

Boombox
Posts: 80
Joined: 18 Oct 2012 05:51

Re: Batch Questions

#4 Post by Boombox » 01 Nov 2012 06:20

.
Can you not just echo the parameter at run time?

Code: Select all

echo %1


Is that what you mean?

http://ss64.com/nt/syntax-args.html

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Batch Questions

#5 Post by Aacini » 01 Nov 2012 08:22

john924xps wrote:This is the syntax:
test [command] [/f]

I want to check whether or not the parameter is being used. How would I do that?

Code: Select all

set Fopt=
set command=%1
if defined command (
   if /I %command% equ /f (
      set command=
   ) else (
      shift
   )
)
if /I "%1" equ "/f" set Fopt=1

Post Reply