|
Answer» Now, I'm MAKING batch files to copy some files in CD to Hard Disk.
The important thing is to make batch file that check the free space of hard disk before copy the files and if the free space is sufficient, the copy command will run.
This is my batch file but I don't know how to compare the free space of hard disk and the file size.
(FOR /f "skip=2 delims=" %%a in ('find "fee space" temp.txt') do echo %%a: this is check the free spce of hard disk. if the file size is 4Gb, how to comapre the free space of hard disk and the file size and make run the copy command.)
@echo off dir c: > temp.txt FOR /f "skip=2 delims=" %%a in ('find "fee space" temp.txt') do echo %%a IF ("Put the batch lines for compare them") copy xcopy "Files" "c:\program files" /s/e pause
No OS was indicated but maybe this will HELP:
Code: [Select]@echo off for /f "tokens=* delims=" %%i in ('dir cdDrive:\ /s /b" do ( for /f "tokens=1-3" %%x in ('dir destinationDrive:\ ^| find /i "bytes free"') do ( if %%~zi LEQ %%z ... ) )
Replace cdDrive with the CD drive letter Replace destinationDrive with the HDD drive letter Fill in your own copy command indicated by the dots
Good luck. Thank you for your reply.
I put your code, but i got the error in 'dir cdDrive:\ /s /b".
the error message is that the format is wrong - "b" do ( for /f "tokens"
Please check it again... Punctuation counts
Code: [Select]@echo off for /f "tokens=* delims=" %%i in ('dir cdDrive:\ /s /b') do ( for /f "tokens=1-3" %%x in ('dir destinationDrive:\ ^| find /i "bytes free"') do ( if %%~zi LEQ %%z ... ) )
This is not executable code, but rather a framework.
Make sure you make the replacements for cdDrive and destinationDrive with WHATEVER is appropriate for your system.
Just a suggestion: The code is written to process one file at a time, so I suggest you use copy and not xcopy. Keep in mind that the %%i variable contains the fully qualified name of the source file.Quote from: Sidewinder on December 22, 2007, 09:06:09 AM Punctuation counts
Code: [Select]@echo off for /f "tokens=* delims=" %%i in ('dir cdDrive:\ /s /b') do ( for /f "tokens=1-3" %%x in ('dir destinationDrive:\ ^| find /i "bytes free"') do ( if %%~zi LEQ %%z ... ) )
This is not executable code, but rather a framework.
Make sure you make the replacements for cdDrive and destinationDrive with whatever is appropriate for your system.
Just a suggestion: The code is written to process one file at a time, so I suggest you use copy and not xcopy. Keep in mind that the %%i variable contains the fully qualified name of the source file.
Thank you for your reply
I'm a really beginner at DOS(Batch file). For example, if i copy the temp.txt file to c:\, the below code is correct? I replaced with your code like that but i cannot still copy the temp.txt file.
@echo off for /f "tokens=* delims=" %%i in ('dir e:\temp.txt /s /b') do ( for /f "tokens=1-3" %%x in ('dir c:\ ^| find /i "bytes free"') do ( if %%~zi LEQ %%z copy e:\temp.txt c:\ ) )
QuoteNow, I'm making batch files to copy some files in CD to Hard Disk.
The important thing is to make batch file that check the free space of hard disk before copy the files and if the free space is sufficient, the copy command will run.
QuoteI replaced with your code like that but i cannot still copy the temp.txt file Based on your posts, the temp.txt file held a DIRECTORY listing that contained the free space value. There is no need for this file as the work will be done in memory.
Judging from your last post, your CD drive is E:, your hard drive is C:, and the target directory is \
Code: [Select]@echo off for /f "tokens=* delims=" %%i in ('dir e:\ /s /b') do ( for /f "tokens=1-3" %%x in ('dir c:\ ^| find /i "bytes free"') do ( if %%~zi LEQ %%z copy "%%i" c:\ ) )
There may be a potential problem in that free space on the directory map is an edited string (complete with commas) and %%~zi is numeric. Let us know
PS. Generally when PEOPLE post code like (FOR /f "skip=2 delims=" %%a in ('find "fee space" temp.txt') do echo %%a, we do not presume them to be beginners.
|