Sign in to follow this  

Bat commands

Recommended Posts

balaton    0

Hello everyone. I'm trying to make a batch file that will allow me to copy all the files from USB to computer and then send them to a certain ftp server. Now, since I've never done much of cmd programming, I've run into some problems.

 

Anyway, here's what I got.

 

testing.vbs contains

 

CreateObject("Wscript.Shell").Run "test.bat",0,True

which basically runs the test.bat file without any windows popping out, since I want it to be done automatically without any hindrance.

 

The test.bat file, where my problems begin, contain

 

@echo off

FOR %%I in (E G H I J K L M N O P Q R S T U V W X Y Z)DO IF exist
XCOPY "H:\*\" "C:\Users\Koala\Documents\batch"   /-y

Basically, what I want this command to do, is to scan for any recently plugged in USB drives and then copy all of the files from it to a folder in documents called batch. But I can't seem to figure out the command to scan for any plugged in data.

 

Any help would greatly be appreciated.

Share this post


Link to post
Share on other sites
jake1eye    6

Here is a VBS script that filter out the USB drive, if you want you could

do your all your tasks with a VBS script.

'-> Object For Script Runtime
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Varibles For Runtime
Dim d,i :d=1
'-> Loop Threw All Local Drives
  For Each i In Fso.Drives
'-> Check For Plug In USB Drive 
   If i.IsReady And i.DriveType = 1 Then 
    d = "Usb Drive Confirm"
    MsgBox d & vbCrLf & i.DriveLetter & vbTab & i.DriveType,4128,"Confirm USB Drive"
    d=2        
   End If 
  Next 
'-> If USB Drive Not Found
  If d = 1 Then
   MsgBox "USB drive is not plug in, plug it in" & vbCrLf & _
          "and rerun the script",4128,"Missing USB Drive"
  End If 

Share this post


Link to post
Share on other sites
balaton    0

Well yeah, I need it to run a copy sequence as soon as it is detected, without displaying any messages, hence the automation.

'-> Object For Script Runtime
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Varibles For Runtime
Dim d,i :d=1
'-> Loop Threw All Local Drives
  For Each i In Fso.Drives
'-> Check For Plug In USB Drive 
   If i.IsReady And i.DriveType = 1 Then 

looks okay, and then I just need to input the command to copy. Is that correct?

Share this post


Link to post
Share on other sites
jake1eye    6

'-> Check For Plug In USB Drive 

If i.IsReady And i.DriveType = 1 Then

d = "Usb Drive Confirm"

MsgBox d & vbCrLf & i.DriveLetter & vbTab & i.DriveType,4128,"Confirm USB Drive"

d=2

End If

Place the code you need between the If and End If, here is a an link on how to use Fso CopyFile

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  

  • Recently Browsing   0 members

    No registered users viewing this page.