1.

Solve : Moving certain file sizes?

Answer»

How would you make a Batch file that moves any file over a certain size to another location?Q: How would you make a Batch file that moves any file over a certain size to another location?
A: We can do it with VBS, if Operational System is Microsoft (XP/2000/2003 etc.)
May be you know. VBS is simple script language (Same Visual Basic SYNTAX)
1. step is execute dir command in to file,
2.step file reading and file moving\deleting

Same process script read to filename and delete for LAST 3 days file . Script is below. Have you changed it?

'on error resume next
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("%comspec% /k dir /b \\server1\C\project\QUALITY\ >> \\server1\C\project\QUALITY\dir.txt")


Wscript.sleep 6000
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
GUN=Weekday(CurrentDate)
hesap=Mid(gun,1,3)
dene =InStr(hesap,1,".")
'Wscript.Echo dene
datex=date-3
tarx=Month(datex)
tary=day(datex)
tarz=year(datex)
tar1=len(Month(datex))
tar2=len(day(datex))
if tar1=1 then tarx="0"&tarx
if tar2=1 then tary="0"&tary
time1=time-0.01
bsaat=mid(time1,1,2)∣(time1,4,2)∣(time1,7,2)
silme=tarz&tarx&tary
'Wscript.Echo silme



Set objTextFile = objFSO.OpenTextFile (" \\server1\C\project\dir.txt", ForReading)


Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , ",")
i=i+1
'Wscript.Echo silme &" : "∣(arrServiceList(0),1,8)
sildosya= arrServiceList(0)
dosdos=mid(arrServiceList(0),1,8)
if silme=dosdos then
silsil=" \\server1\C\project\QUALITY\" & sildosya
yoket="%comspec% /c del " & silsil
Set objExecObject = objShell.Exec(yoket)
end if

Loop
objTextFile.close
Set objExecObject = objShell.Exec("%comspec% /c del \\server1\C\project\QUALITY\dir.txt")But can it be done in a Batch file (because I already have the program that I want to use, but I haven't added this bit YET)?I know you can move files but do you want to move files of a specific size like above 2mb?Quote from: Carbon Dudeoxide on May 01, 2007, 12:27:23 AM

I know you can move files but do you want to move files of a specific size like above 2mb?
Yes (well, above 200kb, actually). So, you got any ideas?I dunno, hang tight and maybe someone else will have the answer to that.
Does it have to be above 200kb, why not the name of the file instead?Quote from: Carbon Dudeoxide on May 01, 2007, 12:47:28 AM
I dunno, hang tight and maybe someone else will have the answer to that.
Does it have to be above 200kb, why not the name of the file instead?

I can't use the file name because the point of my program is for the user to just open the batch file and VOILA, instead of having to access to the folder and renaming every file that needs to be renamed (as it is now, I manually changed the name of the ONLY large file, but it won't work on other computers).the below is an example script. change the for loop parameters to suit your needs
Code: [Select]
for /F "tokens=4* skip=4 delims= " %%A in ('dir /A-D') do (
REM files greater than 40 bytes
if %%A GTR 40 (
echo %%B %%A
rem your move command here
)
)

Thanks. Can you explain what the code means (The command prompt explanation for FOR is a bit too complicated...)?delims mean delimiters so "delims= " mean i am going to use spaces as my delimiter from the dir /A-D output. each "field" separated by the delimiter i call them tokens, so tokens=4* means i am going to get token number 4 onwards, which from the dir /A-D output, is the size in bytes at token 4. Then in the for loop, when i echo %%A , it will the bytes, and if i echo the next token , denoted by %%B, it will be the filename.
I hope you understand what i am saying.


Discussion

No Comment Found