Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Moving certain file sizes  (Read 2985 times)

0 Members and 1 Guest are viewing this topic.

Dark Blade

    Topic Starter
  • Forum Gaming Master


  • Adviser

    Thanked: 24
    • Yes
  • Experience: Experienced
  • OS: Windows XP
Moving certain file sizes
« on: April 30, 2007, 12:06:31 AM »
How would you make a Batch file that moves any file over a certain size to another location?

recruit

  • Guest
Re: Moving certain file sizes
« Reply #1 on: April 30, 2007, 05:59:06 AM »
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)&mid(time1,4,2)&mid(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 &" : "&mid(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")

Dark Blade

    Topic Starter
  • Forum Gaming Master


  • Adviser

    Thanked: 24
    • Yes
  • Experience: Experienced
  • OS: Windows XP
Re: Moving certain file sizes
« Reply #2 on: May 01, 2007, 12:11:04 AM »
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)?

Carbon Dudeoxide

  • Global Moderator

  • Mastermind
  • Thanked: 169
    • Yes
    • Yes
    • Yes
  • Certifications: List
  • Experience: Guru
  • OS: Mac OS
Re: Moving certain file sizes
« Reply #3 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?

Dark Blade

    Topic Starter
  • Forum Gaming Master


  • Adviser

    Thanked: 24
    • Yes
  • Experience: Experienced
  • OS: Windows XP
Re: Moving certain file sizes
« Reply #4 on: May 01, 2007, 12:37:42 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?

Carbon Dudeoxide

  • Global Moderator

  • Mastermind
  • Thanked: 169
    • Yes
    • Yes
    • Yes
  • Certifications: List
  • Experience: Guru
  • OS: Mac OS
Re: Moving certain file sizes
« Reply #5 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?

Dark Blade

    Topic Starter
  • Forum Gaming Master


  • Adviser

    Thanked: 24
    • Yes
  • Experience: Experienced
  • OS: Windows XP
Re: Moving certain file sizes
« Reply #6 on: May 01, 2007, 12:53:35 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).

ghostdog74



    Specialist

    Thanked: 27
    Re: Moving certain file sizes
    « Reply #7 on: May 01, 2007, 01:18:11 AM »
    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
    )
    )


    Dark Blade

      Topic Starter
    • Forum Gaming Master


    • Adviser

      Thanked: 24
      • Yes
    • Experience: Experienced
    • OS: Windows XP
    Re: Moving certain file sizes
    « Reply #8 on: May 01, 2007, 02:34:23 AM »
    Thanks. Can you explain what the code means (The command prompt explanation for FOR is a bit too complicated...)?

    ghostdog74



      Specialist

      Thanked: 27
      Re: Moving certain file sizes
      « Reply #9 on: May 01, 2007, 09:29:45 AM »
      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.