Reputation: 7383
When my Android device (Samsung galaxy s4) is connected to my laptop (Windows 7), I would like to be able to access files on the Android device from the Windows 7 command line. The commands :
cd Computer\GGS4\Phone
or
Computer\GGS4\Phone:
don’t work
FYI, the reason why I need this is to use mp3slpt
from laptop to cut mp3 file on the Android device.
Something like :
D:\temp> mp3splt Computer\GGS4\Podcast\program1.mp3 7.12 7.30 -d out -o program1Extract
Upvotes: 16
Views: 81786
Reputation: 896
I post this as answer considering its high view count relative to similar questions, coming from popuplar search engines.m sorry to post this as answer because I'm unable to verify if this really works on Win7, but it certainly is an answer for the same question for Win10 using PowerShell: https://github.com/nosalan/powershell-mtp-file-transfer/
PowerShell and the Shell.Application
object that is relied upon were already available back in 1999 (see this blog post https://www.computerperformance.co.uk/powershell/com-shell/) , so I believe it can work on Win7.
Disclaimer: I'm not the author of the script, so credits belong to him.
Just for this answer, I copied and pasted code snippets from the linked source to provide it with some explanation.
The trick to access the phone, which should be in "File transfer" mode when connected through USB, is in this part:
$phoneName = "Nokia 7.2"
$o = New-Object -com Shell.Application
$rootComputerDirectory = $o.NameSpace(0x11)
$phoneDirectory = $rootComputerDirectory.Items() | Where-Object {$_.Name -eq $phoneName} | select -First 1
Then you are able to traverse to the directory you want:
$sourceFolder = $phoneDirectory
$phoneFolderName = "Internal shared storage\DCIM\Camera"
foreach($pathSegment in ($phoneFolderName -split "\\"))
{
$sourceFolder = $sourceFolder.GetFolder.Items() | Where-Object {$_.Name -eq $pathSegment} | select -First 1
if($sourceFolder -eq $null)
{
throw "Not found $phoneFolderName folder"
}
}
And finally copy items from the reached sourceFolder to the destination:
function Get-FullPathOfMtpDir($mtpDir)
{
$fullDirPath = ""
$directory = $mtpDir.GetFolder
while($directory -ne $null)
{
$fullDirPath = -join($directory.Title, '\', $fullDirPath)
$directory = $directory.ParentFolder;
}
return $fullDirPath
}
$targetFolder = "E:\Test"
$destDirShell = (new-object -com Shell.Application).NameSpace($targetFolder)
$fullSourceDirPath = Get-FullPathOfMtpDir $sourceFolder
foreach ($item in $sourceFolder.GetFolder.Items())
{
$itemName = ($item.Name)
$fullFilePath = Join-Path -Path $targetFolder -ChildPath $itemName
if(Test-Path $fullFilePath)
{
Write-Host "Element '$itemName' already exists"
}
else
{
$copiedCount++;
Write-Host ("Copying #{0}: {1}{2}" -f $copiedCount, $fullSourceDirPath, $item.Name)
$destDirShell.CopyHere($item)
}
}
Write-Host "Copied '$copiedCount' elements from '$fullSourceDirPath'"
It's also possible to copy files back to the phone. Here I swap the target and source as example, and copy "E:\Test\atestfileonpc.txt" to the phone's "DCIM\Camera" folder:
$sourceDirShell = (new-object -com Shell.Application).NameSpace($targetFolder)
$targetDirShell = $sourceFolder
$item = $sourceDirShell.Items() | Where-Object {$_.Name -eq "atestfileonpc.txt"} | select -First 1
targetDirShell.GetFolder.CopyHere($item)
Pros of this method, is that you don't have to install any additional software on your phone or your Win10 (or Win7 ?) pc. Cons for your question, you have to copy files from phone to your pc, use mp3splt on them, and copy the results back.
Upvotes: 0
Reputation: 41
You can try to install a WebDAV server to the android device, then mount the WebDAV server as a drive on Windows 7, after mounting to a drive, you can access the drive (android folder) from the command line.
Here is a free WebDAV server from Google Play (Of course, there are many other WebDAV servers in Google Play)
And the steps to mount the WebDAV server as a drive on Windows 7
Upvotes: 4
Reputation: 7771
Newer Android devices (primarily) use MTP to communicate with USB hosts. Older devices were identified as mass storage devices. Win7 supports MTP but it doesn't "mount" the device as a drive and the device storage is therefore not available via a file path.
I think the best solution is to copy the file before passing it to mp3splt
:
adb pull Podcast/program1.mp3
mp3splt program1.mp3 7.12 7.30 -d out -o program1Extract
del program1.mp3
You can also develop a Win7 driver that provides a virtual drive using MTP or run an FTP server on your device which you can then associate with a Windows drive (native Win7 example).
Upvotes: 10
Reputation: 5598
On your Android device: Settings->More Settings...->USB Utilities Press "Connect storage to PC" button and plug USB cable. Then press "Turn on USB Storage" and you will see new Drive Letter in My Computer assigned to your Phone.
Now you can run ur command:
D:\temp> mp3splt DRIVE_LETTER:\Podcast\program1.mp3 7.12 7.30 -d out -o program1Extract
Upvotes: 0