ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Post New Requests Here

Batch file to move files (less than total size) from A to B

(1/4) > >>

So excited with the last request that I'm making another sort-of-similar request.

To fill up a USB thumb drive with various YouTube downloaded videos, I use Explorer, detail view, select the first.... down... down...

...and Shift-select the last.  So as to get the total size I want to send to the thumb drive.

Then I drag these files over to the thumb drive.

I'm wondering if there could be a batch file that can help out with the process.

Type into the batch file:

-- Source
-- Destination
-- Total 'upper limit' amount of files desired to be transferred (will end up approximate, of course)

'Order' of files moved, which first, should be by 'filename' order.  (I think that's Windows' default, but not sure.)

Double-click.  Presto.

Source:  d:\video\
Destination:  h:\
Amount of files to transfer:  50 Gb.

Move the files.
Order of move by filename.

Wondering if this is readily doable through batch file (or powershell).

(My hunch is there would have to be a running sum of sizes sent to some cache.  Keep going until....  A batch file to simply move files is easy enough.  The trick here is the total size wanted.)

Thoughts appreciated.

Nicholas Kormanik

Use the last batch file I wrote and count up their size instead of count?

Exactly, highend01.  Just count the total size, if possible, and stop the process before reaching the user-inputed limit.

Don't mean to put the burden on you.  But you certainly aced the last similar request.

I've come across programs for filling up DVDs and CDs with music files.  As I recall, the programs will pick and choose from a set of files, and put as much as possible onto the disk.  Summing total size.

In the present case I just want to start from -- actually, 0001_xyz.mp4.  Then 0002_xyz.mp4.  And on and on until the set total size.  I append the numbers -- serialize -- to all the .mp4 files, to make playing easier (Amazon firestick, using MX Player on the tv, plays in the order of filename, thus the numbers).

A 3rd party file manager like Directory Opus shows you the size of the files you selected.

Don't take this the wrong way, but here's a taught. With the amount of file management you need to do, it might be useful to start looking into one of those. Spend the cash and automatize what you can within that software. You have a GUI to work with, In case of Directory Opus, also an extensive manual, the batch scripts you already have can be implemented as a new button in DO and while your automation is busy, you'll have a progress bar to see how far along you are.

Windows Explorer (in any version of Windows) is not a good fit when you need to manage lots of files. It works more or less for tiny to small file-sets. But it is a time sink and RSI inducer when you try to use it with big file-sets. So falling back to scripting appears the next best thing to do. And it is.

However, you seem to be depending with regards to scripting batch files, so it might be handier for you to start considering 3rd party file managers, like: Directory Opus, Total Commander, XYplorer, xplorer2, Double Commander, Free Commander, Altap Salamander, etc. (this is a list of managers I tried and is in order of my preference).

Look here for a list of 26 3rd party file managers. The fact that there are so many, indicates that Windows Explorer is flawed (deeply).

While scripting is an excellent idea for menial file management tasks, you must either learn (and practice) scripting or get a tool for the job. That way, it is much easier to execute your ideas on how you want your files to be managed the moment you have a new idea about how to do that.

The time being lost by writing down your idea, making the request here at DC, waiting for a response and then testing the response, could have been spend on learning how to script or doing the job with a 3rd party file manager.

On a side note: I was not aware of the existence from Multi Commander. I am taking a look at it and am pleased. The fact that is portable, scores high with me, the Directory Opus 4 "look" (Amiga home computers owners know what I'm about) scores high too and you can edit these buttons extensively, but also the main menu and context menu as well. I start to think it should take the place xplorer2 in my list...maybe even one higher.

Highly recommend what Shades said above, invest in a decent file manager.

Doing it a little differently:

Batch file to move files (less than total size) from A to B

Put the shortcut in C:\Users\<user>\AppData\Roaming\Microsoft\Windows\SendTo, edit its Properties to point to wherever you've put the script.

Edit the path to the script:

--- Code: Text ---C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File "C:\PoSh\MoveMovies.ps1"

* Right-click on the folder with the movies (MP4, MKV, FLV, AVI) -> Send To -> MoveMovies
* Select the destination folder
* Enter the gigabyte value of files to move
Hitting Cancel at any requester will exit, as will running out of space, or entering a GB value out of range.

It only checks the available space on the destination once before moving files so if you happen to copy other things to the destination that reduce the expected space then the Move-Item will fail and an error will popup, (in theory).

There's also a popup when it's finished and if you enter a number out of range.

That's about it for error checking, (hey, it's a 100% improvement over my usual error checking routines).

NOTE: Windows doesn't allow Send To on root directories so it won't work for them.  Could always add a couple of lines to call the function to ask for a Source directory instead of having it passed via Send To ... an exercise for the user.

--- Code: PowerShell ---<#  MoveMovies.ps1#>param (  [string]$source) Add-Type -AssemblyName System.Windows.Forms Function Get-Folder {  $objForm = New-Object System.Windows.Forms.FolderBrowserDialog  $objForm.Description = "Select destination folder"  $objForm.SelectedPath = [System.Environment+SpecialFolder]'MyComputer'  $objForm.ShowNewFolderButton = $false  $result = $objForm.ShowDialog()  if ($result -eq "OK") {    return $objForm.SelectedPath  } else {    return $null  }} Function Get-MoveSize {  param (    [int]$max  )  [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')   $title = 'Move Movies'  $msg = "Total GBs of files to move [1-$($max)]: "   $text = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)  return (($text/1) * 1Gb)} Function Send-Notification {#  param (    [string]$msg,    [int]$type  )  $wshell = New-Object -ComObject Wscript.Shell -ErrorAction Stop  $wshell.Popup($msg, 0, "MoveMovies", $type) | Out-Null}  $dest = (Get-Folder)if ($dest -ne $null) {  # Get disk volume label  $dDrive = ($dest | Split-Path -Qualifier)  # Get disk free space, round down to nearest whole number  $dFree = [math]::Round((gwmi Win32_LogicalDisk -Filter "DeviceID='$($dDrive)'").FreeSpace / 1Gb)} else {  break} $moveSize = (Get-MoveSize $dFree)if (($moveSize -lt 1) -or ($moveSize -gt ($dFree * 1Gb))) {  Send-Notification "Input outside acceptable range!" 16  break} Write-Host $dest $moveSize $dDrive ($dFree * 1Gb) # Get list of videos in source directory$videos = (Get-ChildItem "$($source)\*" -Include *.mp4,*.mkv,*.flv,*.avi | Sort Name)for ($i = 0; $i -lt $videos.Count; $i++) {  if ($videos[$i].Length -lt $moveSize) {    Move-Item -LiteralPath "$($videos[$i].FullName)" -Destination "$($dest)"    if ($?) {      $moveSize -= $videos[$i].Length    } else {      Send-Notification "Moving file failed!" 16      break    }  } else {    Send-Notification "Maximum number of files moved into space available/allowed" 64    break  }}


[0] Message Index

[#] Next page

Go to full version