Jump to content

Xcopy from USB pen


Recommended Posts

I know this can be done in a Batch file to detect the CDROM

for %%i in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if exist %%i:\WIN51 set CDROM=%%i:

, but how can you do it for a USB pen?

I have files on my pen that need to be copied to 30 machines. I've created a Xcopy batch file:

xcopy /y /q "y:\TEST_ONE" "v:\"

But where Y: is might be V: on another machine, so i need the Batch file to look for the pen.

Is this possible?

Did i explaine it right :}

I dont think i posted this in the correct pace? :whistle:

Link to comment
Share on other sites


You could create a folder named 'USB' on the pendrive and then use this code to detect on wich drive it resides.

FOR %%i IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\USB set USB=%%i:

Now,

%USB% = pendrive:\

Edited by pawls
Link to comment
Share on other sites

I do not know if this will work since I do not have a pen drive.

This is a VBS that uses the FileScriptingObject to list the drives

Save As Whatever.VBS

This color text are for either the file or folder you want copy remove all 4 of

these '''' to make active. These check to see if they exists

This color text is where you add your own to go locations and file or folder for target

Example

Where the file or folder goes to

EndLoc = "C:\SOMEFOLDER\NEXTFOLDER

This is for the drive letter

Example File

Target = "SOMEFILE.EXE"

In the script this tranlates to

Drv & "\SOMEFILE.EXE"

Example Folder

Target = "\FOLDER_001\FOLDER_002"

In the script this tranlates to

Drv & "\FOLDER_001\FOLDER_002"

Const OverwriteExisting = True '''' PREVENTS THE FILE OR FOLDER WAS THERE DIALOG

Dim Drv, EndLoc, Fso, Target: Set Fso = CreateObject("Scripting.FileSystemObject")

Set colDrives = Fso.Drives

EndLoc = (FILL_IN_WHERE_IT_GOES)

Target = (THE_FOLDER_OR_FILE)

For Each objDrive in colDrives

If objDrive.IsReady = True Then

Drv = objDrive.DriveLetter & ":\"

'''' If File

'''' If Fso.FileExists(Drv & Target) : Then : Fso.CopyFile(Drv & Target),(EndLoc),OverwriteExisting : End If

'''' If Folder

''''If Fso.FileExists(Drv & Target) : Then : Fso.CopyFile(Drv & Target),(EndLoc),OverwriteExisting : End If

End If

Next

Edited by gunsmokingman
Link to comment
Share on other sites

Not sure where you have the batch file stored. If you put it on the USB drive you can use %~d0 to get the drive letter or %~dp0 to get the full path to the batch file.

Example batch file D:\Temp\t.bat

@echo off

echo %~dp0

echo %~d0

Output

D:\Temp\

D:

Link to comment
Share on other sites

@Pawls

If only it was that simple :no: Didnt work

@gunsmokingman

Thanks for your suggestion but a .vbs script will be picked up as a virus or dangerous file. Would rather use Batch files if possible.

This is my current baych file. Y=pendrive

cls
@echo off


Title Coping Files to uesrprofile and Shortcuts to Desktop
MODE CON COLS=80 LINES=30
color 4f

xcopy /y "Y:\LessonMaterial\TrainingData\Shortcuts\*.*" "%userprofile%\desktop"
xcopy /e /k /i /c /r /y "Y:\LessonMaterial" "%userprofile%\Personal\"

ECHO Shutting down computer in 5 seconds
Shutdown -s /f /t 5 /c "One step to gooooooooo............"

@FrankE9999

Could you incorpreate your suggestion into my Batch file, not to sure what your getting at. Thanks

Edited by codeblue
Link to comment
Share on other sites

You could use the ".\" to inform the script to start in the same place as the script...so for your script it would be something like this:

cls
@echo off


Title Coping Files to uesrprofile and Shortcuts to Desktop
MODE CON COLS=80 LINES=30
color 4f

xcopy /y ".\LessonMaterial\TrainingData\Shortcuts\*.*" "%userprofile%\desktop"
xcopy /e /k /i /c /r /y ".\LessonMaterial" "%userprofile%\Personal\"

ECHO Shutting down computer in 5 seconds
Shutdown -s /f /t 5 /c "One step to gooooooooo............"

That's assuming that both the script and the LessonMaterial folder are in the root of the drive...or parallel to each other. Remember, this uses the place the script runs from as it's base, so if it's running from the local temp dir then it's not gonna do you any good. But if you are running the script straight from the drive then it should work. Couple this with the autorun idea mentioned earlier and those 30 will fly by.

Link to comment
Share on other sites

@Bi0haZarD

So on the PEN i need an autorun.inf file containing the following:

[autorun]
open=Training data.cmd

TrainingData in the name of the batch file

@Inthewayboy

Thanks, ".\" works :thumbup

Although not quite what i was looking for it works and i can move on !!

Anyone know how to add this to my script?:

Do you want to shutdown the PC? Y/N
If Y Shutdown (goto?)
If N exit

Edited by codeblue
Link to comment
Share on other sites

bts?

I have this:

set answer=y
set /p answer=Do you want to Shutdown PC?
if not "%answer:~0,1%"=="y" goto :END

ECHO Shutting down computer in 5 seconds
Shutdown -s /f /t 5 /c "One step to gooooooooo............"

:END

But the user needs to hit enter after 'y'. Not a problem, but not ideal.

Another minor issue is that the Dos screen isnt the active screen, the user needs to click in it to enter 'Y'. Is there a command to force the dos screen to become the active screen?

Edited by codeblue
Link to comment
Share on other sites

Dunno why I slipped in a CLS up there. :blushing:

Anyhow this works for me:

FOR %%i IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%i:\USB set USB=%%i:

CLS
%USB%
DIR

Makes %USB% the driveletter of the usb-drive.

Link to comment
Share on other sites

Hi,

If you want to accomplish an automatic XCOPY action after inserting the USB pendrive without user interference, forget it.

Autorun files will not work on USB pendrives. I have been trying this for a while, and a long google surch revealed a Microsoft explanation that USB pendrives are treated different in windows than CD-ROM's.

A way to do this is to have a batch file on the host machines that will look for a specific map on the pendrive. Example: Create a folder named: 012345678

On the host machine , start a batch task that will look on

d: e: f: .... z: for a folder 12345678 using errorcodes.

When the folder is found, you have your drive and XOPY the files you need.

It can be a very simple batch file that you can run in windows task scheduler every 10 minutes (or less if it is a very regular task).

Use CMDow.exe to hide this batch file from the users working behind the machines.

Succes!

Ivo

Link to comment
Share on other sites

@codeblue

i tried the autorun.inf last night on my 128mb pendrive, seems that only the icon= line works. :(

could'nt get mine to autorun without some sort of 3rd party program. and i haven't tried any of the scripts mentioned in this post.

although.., i was able to get the explorer.exe shell to show up with the contents of the drive by using:

[autorun]icon=setup.exe

*was using the setup.exe that comes with the windows xp cd* but still no autorun.

just kinda curious, but wouldn't this be easier with a cd... sure you can't use it again, unless its a cd-rw.. but at least with that you can setup a autorun...

Edited by Bi0haZarD
Link to comment
Share on other sites

@Pawls

If only it was that simple :no: Didnt work

@gunsmokingman

Thanks for your suggestion but a .vbs script will be picked up as a virus or dangerous file. Would rather use Batch files if possible.

This is my current baych file. Y=pendrive

cls
@echo off


Title Coping Files to uesrprofile and Shortcuts to Desktop
MODE CON COLS=80 LINES=30
color 4f

xcopy /y "Y:\LessonMaterial\TrainingData\Shortcuts\*.*" "%userprofile%\desktop"
xcopy /e /k /i /c /r /y "Y:\LessonMaterial" "%userprofile%\Personal\"

ECHO Shutting down computer in 5 seconds
Shutdown -s /f /t 5 /c "One step to gooooooooo............"

@FrankE9999

Could you incorpreate your suggestion into my Batch file, not to sure what your getting at. Thanks

If you are running Windows XP or 2000 and the script you are trying to run is on the key.

%~d0 expands to the drive letter of the script which will be the same as the drive letter of the key since the batch file you are running is on the key.

xcopy /y "%~d0\LessonMaterial\TrainingData\Shortcuts\*.*" "%userprofile%\desktop"

xcopy /e /k /i /c /r /y "%~d0\LessonMaterial" "%userprofile%\Personal\"

Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...