Jump to content



Photo

Bat commands


  • Please log in to reply
3 replies to this topic

#1 balaton

balaton

    Neowinian

  • Joined: 09-December 13

Posted 09 December 2013 - 22:58

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.




#2 jake1eye

jake1eye

    Neowinian

  • Joined: 02-April 03
  • Location: New Westminster

Posted 10 December 2013 - 18:28

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 



#3 OP balaton

balaton

    Neowinian

  • Joined: 09-December 13

Posted 10 December 2013 - 20:57

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?



#4 jake1eye

jake1eye

    Neowinian

  • Joined: 02-April 03
  • Location: New Westminster

Posted 10 December 2013 - 23:03

'-> 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



Click here to login or here to register to remove this ad, it's free!