Installation

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
MLGsuperGame414
Posts: 54
Joined: 10 Nov 2011 20:40

Installation

#1 Post by MLGsuperGame414 » 31 Mar 2013 21:13

Is there any simple way to take myfile.txt located on my desktop and run a batch file that puts it in my documents? Kinda like an installer.

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

Re: Installation

#2 Post by foxidrive » 31 Mar 2013 21:18

Use the move command to move it from your desktop to documents, or the copy command if you want a copy of it.

These give you the syntax:

move /?

copy /?

MLGsuperGame414
Posts: 54
Joined: 10 Nov 2011 20:40

Re: Installation

#3 Post by MLGsuperGame414 » 01 Apr 2013 12:08

Okay next question would be how can I check a directory? and then use an if statement to see if its empty.

Ex checking my desktop and if its empty an if statement runs that says the dir is empty. I dont really know how to use the if statement so could someone provide an example?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Installation

#4 Post by Squashman » 01 Apr 2013 12:38

set empty=Y
for /F %%G in ('dir /b c:\temp') do set empty=N

IF "%empty%"=="Y" echo Directory is Empty
IF "%empty%"=="N" echo Directory is not Empty Empty

MLGsuperGame414
Posts: 54
Joined: 10 Nov 2011 20:40

Re: Installation

#5 Post by MLGsuperGame414 » 01 Apr 2013 12:59

So set empty=Y creates a variable? and doesn't Y have something to do with the dir?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Installation

#6 Post by Squashman » 01 Apr 2013 13:03

Why not test the code as I gave it to you.
Create an empty folder: C:\temp
Then test the code.

Then put a file in the C:\Temp and test the code.

MLGsuperGame414
Posts: 54
Joined: 10 Nov 2011 20:40

Re: Installation

#7 Post by MLGsuperGame414 » 01 Apr 2013 13:07

I'm going to test it I just want a better understanding.

Edit although it didn't seem to work. Just keeps giving me the message that the Dir is empty.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Installation

#8 Post by Squashman » 01 Apr 2013 13:24

works just fine.

Code: Select all

C:\batch files\empty>dir /B C:\temp

C:\batch files\empty>empty.bat
Directory is Empty

C:\batch files\empty>echo notempty>C:\temp\test.txt

C:\batch files\empty>empty.bat
Directory is not Empty Empty

C:\batch files\empty>

MLGsuperGame414
Posts: 54
Joined: 10 Nov 2011 20:40

Re: Installation

#9 Post by MLGsuperGame414 » 01 Apr 2013 14:24

Alright I'm just dumb I forgot to change temps to the Dir I was using. Okay next thing I would like to know would this work?

Code: Select all

set empty=Y
for /F %%G in ('dir /b C:\Users\blarg\Desktop\not') do set empty=N

IF "%empty%"=="Y" echo Directory is Empty
IF "%empty%"=="N" del filename.txt


So if I had a text file in that dir would it delete it?

And if not could I search for any files and delete them with a variable? Like %filename% or $filename? I know those wouldn't work, but could something like that work where if any file was found it would be deleted?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Installation

#10 Post by Squashman » 01 Apr 2013 15:05

Well we need to clarify a few things.

Currently the code I gave you will tell if the directory is not empty if there are folders or files in the directory.

So do you just want to delete the files in the directory or the folders and files?

If you want everything removed from the directory (files and folders) then the easiest thing to do would be to just delete the NOT directory and then recreate it.

Code: Select all

IF "%empty%"=="N" RD /S Q "C:\Users\blarg\Desktop\not"
MD "C:\Users\blarg\Desktop\not"


If you need to keep sub folders inside the NOT folder then I would change the FOR loop and delete the file in there.

Code: Select all

for /F "delims=" %%G in ('dir /a-d /b C:\Users\blarg\Desktop\not') do del "%%~G"
Last edited by Squashman on 01 Apr 2013 17:11, edited 1 time in total.
Reason: Fixed code

MLGsuperGame414
Posts: 54
Joined: 10 Nov 2011 20:40

Re: Installation

#11 Post by MLGsuperGame414 » 01 Apr 2013 15:23

In your for, loop what is /f?

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

Re: Installation

#12 Post by foxidrive » 01 Apr 2013 15:38

It is a modifier to run a type of FOR IN DO command.

Type this and read the help:

FOR /?


If you tell us what you want to do, and in what order, then someone can help you achieve it.
In the example above for for /f you will need to use the "delims=" option to handle long filenames.

MLGsuperGame414
Posts: 54
Joined: 10 Nov 2011 20:40

Re: Installation

#13 Post by MLGsuperGame414 » 01 Apr 2013 18:45

Okay what I am trying to do is make an installer to install some files in a zip folder. For now I guess we could use the file names of readme.txt and filetwo.cfg I want the installer to check if the files have been moved by checking the zip folder they came in first, then checking the new Dir they were suppose to be moved to and displaying a message that the files have been moved successfully or unsuccessfully. I then want the installer to delete itself. I have the deleting part and the moving part done.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Installation

#14 Post by Squashman » 01 Apr 2013 19:25

And what command line zip application are you using?

MLGsuperGame414
Posts: 54
Joined: 10 Nov 2011 20:40

Re: Installation

#15 Post by MLGsuperGame414 » 01 Apr 2013 19:36

WinRAR

Post Reply