Page 1 of 3
Installation
Posted: 31 Mar 2013 21:13
by MLGsuperGame414
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.
Re: Installation
Posted: 31 Mar 2013 21:18
by foxidrive
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 /?
Re: Installation
Posted: 01 Apr 2013 12:08
by MLGsuperGame414
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?
Re: Installation
Posted: 01 Apr 2013 12:38
by Squashman
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
Re: Installation
Posted: 01 Apr 2013 12:59
by MLGsuperGame414
So set empty=Y creates a variable? and doesn't Y have something to do with the dir?
Re: Installation
Posted: 01 Apr 2013 13:03
by Squashman
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.
Re: Installation
Posted: 01 Apr 2013 13:07
by MLGsuperGame414
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.
Re: Installation
Posted: 01 Apr 2013 13:24
by Squashman
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>
Re: Installation
Posted: 01 Apr 2013 14:24
by MLGsuperGame414
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?
Re: Installation
Posted: 01 Apr 2013 15:05
by Squashman
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"
Re: Installation
Posted: 01 Apr 2013 15:23
by MLGsuperGame414
In your for, loop what is /f?
Re: Installation
Posted: 01 Apr 2013 15:38
by foxidrive
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.
Re: Installation
Posted: 01 Apr 2013 18:45
by MLGsuperGame414
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.
Re: Installation
Posted: 01 Apr 2013 19:25
by Squashman
And what command line zip application are you using?
Re: Installation
Posted: 01 Apr 2013 19:36
by MLGsuperGame414
WinRAR