Installation
Moderator: DosItHelp
-
- Posts: 54
- Joined: 10 Nov 2011 20:40
Installation
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
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 /?
These give you the syntax:
move /?
copy /?
-
- Posts: 54
- Joined: 10 Nov 2011 20:40
Re: Installation
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?
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
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
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
-
- Posts: 54
- Joined: 10 Nov 2011 20:40
Re: Installation
So set empty=Y creates a variable? and doesn't Y have something to do with the dir?
Re: Installation
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.
Create an empty folder: C:\temp
Then test the code.
Then put a file in the C:\Temp and test the code.
-
- Posts: 54
- Joined: 10 Nov 2011 20:40
Re: Installation
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.
Edit although it didn't seem to work. Just keeps giving me the message that the Dir is empty.
Re: Installation
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>
-
- Posts: 54
- Joined: 10 Nov 2011 20:40
Re: Installation
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?
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?
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
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.
If you need to keep sub folders inside the NOT folder then I would change the FOR loop and delete the file in there.
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
Reason: Fixed code
-
- Posts: 54
- Joined: 10 Nov 2011 20:40
Re: Installation
In your for, loop what is /f?
Re: Installation
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.
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.
-
- Posts: 54
- Joined: 10 Nov 2011 20:40
Re: Installation
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
And what command line zip application are you using?