Jump to content

Batch Scripting help :)

Flanelman

Hi, im just starting to learn batch scripting and i have a project due and one of the questions i don't even understand. all i have done so far is open up a program to write it in, and make folders to store these files in "output" "input" " processing" i am yet to actually do anything.

Q) "list all the hidden files in the root directory of the C: drive -- output the listing to a file called "inputData.txt" in the "input" subfolder."

i dont have any files so i don't know what hidden files it's talking about nor do i know what the file "inputdata.txt" has to contain?

I understand this is probably really hard to answer because of lack of info which is why im struggling because it hasn't told me how to actually do anything yet :P

any help would be very much appreciated. thanks :)

Link to comment
Share on other sites

Link to post
Share on other sites

dir /ah

all hidden files and hidden directories in the directory that you are currently in.

dir /ah-d

all hidden files in the directory that you are currently in.

dir /a

all files and directories including hidden files and hidden directories in the directory that you are currently in.

 

 

Will leave you to work out using it in the code, can post again if you get stuck.

 

-Vbox

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

dir /ah

all hidden files and hidden directories in the directory that you are currently in.

dir /ah-d

all hidden files in the directory that you are currently in.

dir /a

all files and directories including hidden files and hidden directories in the directory that you are currently in.

 

 

Will leave you to work out using it in the code, can post again if you get stuck.

 

-Vbox

 

Thank you for your help :) How would I then output the list of hidden files to a new file that doesn't already exist? the file i'm wanting to list to being in a different folder to the file im currently working on? (i hope that makes sense :P )..  :)

Link to comment
Share on other sites

Link to post
Share on other sites

Thank you for your help :) How would I then output the list of hidden files to a new file that doesn't already exist? the file i'm wanting to list to being in a different folder to the file im currently working on? (i hope that makes sense :P )..   :)

echo dir /ah-d > input/input data.txt

that should do it, i'm on a chromebook right now so can't really test.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

echo dir /ah-d > input/input data.txt

that should do it, i'm on a chromebook right now so can't really test.

 

will this make the file? or will i have to make the file and then just assign the data to it? :)

Link to comment
Share on other sites

Link to post
Share on other sites

will this make the file? or will i have to make the file and then just assign the data to it? :)

 

that command will create the file if it doesn't exist or will rewrite the file with the new data if it does.

 

if you want to add new data to the end of a file you use >>

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

that command will create the file if it doesn't exist or will rewrite the file with the new data if it does.

 

if you want to add new data to the end of a file you use >>

how for question 8 would I backup that "inputdata.txt" file to the root of C: and change the file extension to .BAK? i've not been able to find anything on google about it :(

would this be how to copy it?

Copy "C:\inputdata.txt" "C:\inputdata.bak" 

 

Link to comment
Share on other sites

Link to post
Share on other sites

how for question 8 would I backup that "inputdata.txt" file to the root of C: and change the file extension to .BAK? i've not been able to find anything on google about it :(

Copy "\inputdata.txt" "C:\inputdata.bak" 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

Copy "\inputdata.txt" "C:\inputdata.bak" 

Oh cool so i got that one :D and how would i create a folder with sub folders?

would this work?

"md c:\MyBatchScriptfileassignment

md c:\MyBatchScriptfileassignment/input
md c:\MyBatchScriptfileassignment/output
md c:\MyBatchScriptfileassignment/processing"?
Link to comment
Share on other sites

Link to post
Share on other sites

 

Oh cool so i got that one :D and how would i create a folder with sub folders?

would this work?

"md c:\MyBatchScriptfileassignment

md c:\MyBatchScriptfileassignment/input
md c:\MyBatchScriptfileassignment/output
md c:\MyBatchScriptfileassignment/processing"?

with the top one being a folder in c: and the other 3 being sub folders to that first folder?

Link to comment
Share on other sites

Link to post
Share on other sites

 

Oh cool so i got that one :D and how would i create a folder with sub folders?

would this work?

"md c:\MyBatchScriptfileassignment

md c:\MyBatchScriptfileassignment/input
md c:\MyBatchScriptfileassignment/output
md c:\MyBatchScriptfileassignment/processing"?

 

 

once you've made the first one with md c:\MyBatchScriptfileassignment you can just CD to it

MD c:\MyBatchScriptfileassignmentCD MyBatchScriptfileassignmentMD inputMD outputMD processing

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

 

once you've made the first one with md c:\MyBatchScriptfileassignment you can just CD to it

MD c:\MyBatchScriptfileassignmentCD MyBatchScriptfileassignmentMD inputMD outputMD processing

Oh okay that's pretty cool :) Thanks again for helping by the way i appreciate it very much :)

there is the command "goto" which i know of, but how would i make it go to the C drive? would it just be as simple as " goto "C:\" "? 

Link to comment
Share on other sites

Link to post
Share on other sites

 

 

once you've made the first one with md c:\MyBatchScriptfileassignment you can just CD to it

MD c:\MyBatchScriptfileassignmentCD MyBatchScriptfileassignmentMD inputMD outputMD processing

Oh okay that's pretty cool :) Thanks again for helping by the way i appreciate it very much :)

there is the command "goto" which i know of, but how would i make it go to the C drive? would it just be as simple as " goto "C:\" "? 

 

 

GOTO is more like a function

SET /P M=Type 1, 2, 3, or 4 then press ENTER:IF %M%==1 GOTO ONEIF %M%==2 GOTO TWO:ONEecho hello from one:TWOecho hello from two

to go to c:\ you would use 

CD C:

how ever i read that you're requited to make to go to c:\ from any location (i assume another drive) in which case use

cd /d c:

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

 

GOTO is more like a function

SET /P M=Type 1, 2, 3, or 4 then press ENTER:IF %M%==1 GOTO ONEIF %M%==2 GOTO TWO:ONEecho hello from one:TWOecho hello from two

to go to c:\ you would use 

CD C:

how ever i read that you're requited to make to go to c:\ from any location (i assume another drive) in which case use

cd /d c:

For Q10, would this be right?

set PATH = %PATH%;C:\MyBatchScriptFileAssignment\Processing

echo %PATH%

Link to comment
Share on other sites

Link to post
Share on other sites

For Q10, would this be right?

set PATH = %PATH%;C:\MyBatchScriptFileAssignment\Processing

echo %PATH%

 

I'm not actually sure about q10 sorry. Seeing as it hasn't asked to do anything with searching. seems like a bit on an odd ball.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

For Q10, would this be right?

set PATH = %PATH%;C:\MyBatchScriptFileAssignment\Processing

echo %PATH%

Do you still need help? If so , just reply to this.

Also its really bad practice in batch to not Quote your variables (besides when using set /p)

So do

set "path=%path%;whatever"
Its because trailing spaces count , and you cant use more than one Word.

So if you do set letter=b && set name=joe

It will set letter to "b " and name to "joe "

A riddle wrapped in an enigma , shot to the moon and made in China

Link to comment
Share on other sites

Link to post
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

×