Jump to content

Looking For A Command Line Util


Mekrel

Recommended Posts


Yeah im trying to get it to be very informative now. ill post code in a second and atm im just testing with loads of text files. :)

@echo off
:Check total files in directory
set checkpath="C:\Program Files\test"
for /f "tokens=3 delims=) " %%i IN ('dir %checkpath% /s ^| find "bytes" ^| find /v "free"') DO SET usedspace=%%i
for /f "tokens=1-5" %%i IN ('echo %usedspace%') DO set usedspace=%%i%%j%%k%%l%%m

:Check freespace in C: drive
for /f "tokens=3 delims=) " %%i IN ('dir C:\ ^| find "bytes free"') DO SET freespace=%%i
for /f "tokens=1-5" %%i IN ('echo %freespace%') DO set freespace=%%i%%j%%k%%l%%m
if %freespace% LEQ %usedspace% (
 echo "Not enough file space on C Drive"
 PING 127.0.0.1 -n 10>NUL
 ) ELSE (
 echo "Enough File space on C Drive, Copying files to C:\"
 PING 127.0.0.1 -n 10>NUL
 XCOPY "C:\Program Files\Test" "C:\Test" /E /V /I /Y /Z /F
 PING 127.0.0.1 -n 10>NUL
 EXIT
 )
 
:Check freespace in D: drive
for /f "tokens=3 delims=) " %%i IN ('dir D:\ ^| find "bytes free"') DO SET freespace=%%i
for /f "tokens=1-5" %%i IN ('echo %freespace%') DO set freespace=%%i%%j%%k%%l%%m
if %freespace% LEQ %usedspace% (
 echo "Not enough file space on D Drive"
 PING 127.0.0.1 -n 10>NUL
 ) ELSE (
 echo "Enough File space on D Drive, Copying files to D:\"
 PING 127.0.0.1 -n 10>NUL
 XCOPY "C:\Program Files\Test" "D:\Test" /E /V /I /Y /Z /F
 PING 127.0.0.1 -n 10>NUL
 EXIT
 )
 
:Check freespace in E: drive
for /f "tokens=3 delims=) " %%i IN ('dir E:\ ^| find "bytes free"') DO SET freespace=%%i
for /f "tokens=1-5" %%i IN ('echo %freespace%') DO set freespace=%%i%%j%%k%%l%%m
if %freespace% LEQ %usedspace% (
 echo "Not enough file space on E Drive"
 echo "Not enough space on any of the drives!"
 PING 127.0.0.1 -n 10>NUL
 ) ELSE (
 echo "Enough File space on E Drive, Copying files to E:\"
 PING 127.0.0.1 -n 10>NUL
 XCOPY "C:\Program Files\Test" "E:\Test" /E /V /I /Y /Z /F
 PING 127.0.0.1 -n 10>NUL
 EXIT
 )
pause
exit

using ping is probably a unclean way of doing it :P

ohhh also, this person im sure said he is using drives on another computer on his network. How do i make the changes so the .cmd files checks the drives on another computer?

Link to comment
Share on other sites

w8 , save yourself the time he tells mw he has already got the storage locations mapped to W X Y Z drives :)

so looks like job solved, he just has to edit it himself. im gonna keep this for myself too. When i used to make Quake3 engine videos, to move the files when my hdd gets full to another one :)

I've set up a pc which records tv programs on to a 80gb hard disk (running windows xp) but I'm having trouble writing a .bat file which will move everyrhing in c:\recorded tv\ onto another pc which I use for storage. The second pc has 4 200gb hard disks (mapped to W,X,Y,Z). In the .bat file i need it to attempt to move the files onto drive W, if that's full then try drive X and so on.

I have tried using the Xcopy command but the problem with using that is that i'll have to add a line after that to erase the files off the source disk. If i did that then when the xcopy failed (due to first disk being full) the files will still get erased.

Also i've tried the move command but if the first drive is full then it requires user intervention before carrying on and there are no switches to disable this.

What i really need is some sort of IF statement when using xcopy so the erase command is only carried out if it moves the files successfuly. I have no idea how IF statements are laid out (have only programmed in VB) or if it's even possible.

The final method i tried was to search for an xmove.exe (same as xcopy but moves the files). I found one but it was shareware so after a week it started displaying a message which required you to press a key every time i used it (i don't have a keyboard on that pc so it's a bit of a problem).

This was his original post :)

If you can make the .cmd file to look nice and user friendly and more efficient than what i have done un4given1 then please do! Wow your good at command line :o

Link to comment
Share on other sites

Knowing script isn't always about knowing all of the commands. It's about knowing what all commands can do and how to use them together to get your desired result. The command I used wasn't just a FOR command. It was a DIR and a FIND and a SET command all used together to get the desired result. Just keep practicing and always use the help files with a command to see what it can do. You would be amazed what all you can do with command scripts. I was once told that it was impossible to create a timer using batch script. Did it. If something can't be done using the built in commands in Windows XP you can always bet there will be an application out there that will help.

Link to comment
Share on other sites

Although 1 thing he did say he wanted was some kind of way to tell that the files had been copied succesfully before running the Del command on the original files :)

I was thinking of checking the original usedspace with another usedspace1 variable (which checked the used space of the new directry the files were copied to) but there could be lots of anonamlies with that, such as extra files and such.

Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...