Sign in to follow this  
Followers 0
am632

need help copying files to pre-defined card reader

8 posts in this topic

Hi,

I dont know where to start with this 1, but basically I want a script which will copy files in a defined folder to a specific memory card reader based on its device id if this is possible, so lets say I have this simple copy script like...

DirCopy("\FolderContainingFilesToCopy", CARD_READER_ID)

I know this command wont work but this is the best way i can explain what I want to be able to do. The reason I dont want to specify a drive letter is because it may change especially if I have other readers/devices connected. & even if I have 5 different card readers connected, it will automatically copy the files directly to the card reader I want without the user having to specify it.

Do you see what I'm trying to do?

If this cant be done in autoit does anyone know a way I can acheive this?

Thanks

Share this post


Link to post
Share on other sites



has a few interesting ways of detecting USB connected "drives" that might work for card readers, as long as the card reader has a memory card in it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Hi,

thank you for this - I'll have a good read through tonight

Share this post


Link to post
Share on other sites

You could also iterate through an array of drive letters and do this:

if StringInStr($driveletter,"CARD_NAME") <=0 then

Hi,

i just saw your post after i typed a replie out :) so if im correct what you mean is if I call the card something specific - it will go through each drive letter untill it finds the drive with the specified label then use that?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You can also put a label on the card, and then iterate through WMI to find the volume name and letter. Something like this should work (tested on a USB stick, not a card):

Edit: Forgot the error handler

$oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
$sShell = ObjCreate("Wscript.Shell")
$sFSO = ObjCreate("Scripting.FileSystemObject")
$aDrives = $sFSO.Drives

 For $element in $aDrives
   If $element.VolumeName = "Testing" Then MsgBox(0, "", $element.DriveLetter)
 Next

Func _ErrFunc()
 MsgBox(0, $element.DriveLetter, "Volume has no name")
EndFunc
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

am632,

Building on JLogan3013's suggestion. You can prompt the user for the correct volume (in this case "SYS TOOLS") and continue once the volume is mounted.

$oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

$sShell = ObjCreate("Wscript.Shell")
$sFSO = ObjCreate("Scripting.FileSystemObject")
local $aDrives = $sFSO.Drives, $vol

$vol = _check_volumes()

while not $vol
    msgbox(0,'Volume Not Mounted','Please mount the "SYS TOOLS" volume in any drive')
    $vol = _check_volumes()
wend

func _check_volumes()

    For $element in $aDrives
        If $element.VolumeName = "SYS TOOLS" then return $element.DriveLetter
    Next

endfunc

ConsoleWrite('Starting copy...output volume = ' & $vol & ':' & @LF)

Func _ErrFunc()
 ; this is here to keep the scipt from abending by capturing errors from FileSystemObject
EndFunc

Incidentally, WMI is not being used. This is a VBS object.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

You can also put a label on the card, and then iterate through WMI to find the volume name and letter. Something like this should work (tested on a USB stick, not a card):

Edit: Forgot the error handler

$oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
$sShell = ObjCreate("Wscript.Shell")
$sFSO = ObjCreate("Scripting.FileSystemObject")
$aDrives = $sFSO.Drives

For $element in $aDrives
If $element.VolumeName = "Testing" Then MsgBox(0, "", $element.DriveLetter)
Next

Func _ErrFunc()
MsgBox(0, $element.DriveLetter, "Volume has no name")
EndFunc

Hi thanks for this, this can work for what I want, I changed the script slightly to this...

$oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
$sShell = ObjCreate("Wscript.Shell")
$sFSO = ObjCreate("Scripting.FileSystemObject")
$aDrives = $sFSO.Drives
For $element in $aDrives
   If $element.VolumeName = "dkjsfb8956" Then MsgBox(0, "", "Your card reader has been found on drive " & $element.DriveLetter & ":\ and is named" & " " & $element.VolumeName)
Next
Func _ErrFunc()
Sleep(100)
EndFunc

and it does work - so regardless of the drive letter it will find the card labeld dkjsfb8956.

I can work with this, the only down side to this is if the card has been formatted by the user and has a generic label the script wont work if there are other drives with the same label right? so would it be possible to search for the drive based on its hardware id? I know this will also stop working if there are 2 identical readers connected at the same time but thats less likely than multiple drives with the label 'removable drive' for example, u know what i mean?

this is brilliant tho and I like how simple the script is which I can work around my existing script. Also I havn't done anything with autoit and the WMI before. are there some tutorials or examples I can read to learn more about this in general? I think this will be a good thing to learn

thanks for your help

Aaron

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0