Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: pball
I am trying to copy every file and folder from a usb drive to my computer. I believe I need to use the xcopy command. So then how do I get the source folder to change with the drive letter since the drive letter may change.

The way to keep the drive letter from changing is to assign the letter.
=====================================
If at first you don't succeed, you're about average.M2

assuming you have 1 usbdrive. here's a vbscript. save as somename.vbs and run from command prompt. cscript somename.vbs
[code]
Dim oFSO, oDrive,objFolder,oUsbDrive,oDestination
Const USBDRIVE=1
oDestination = "c:\test"
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
'Get USB drive letter
For Each oDrive In oFSO.Drives
....If oDrive.DriveType = USBDRIVE And oDrive.DriveLetter <> "A" Then
....WScript.Echo "found usb at", oDrive.DriveLetter
....oUsbDrive = oDrive.DriveLetter & ":\"
....End If
Next
Sub CopyFiles(oPath, oDst)
....Set objFolder = oFSO.GetFolder(oPath)
....For Each Files In objFolder.Files
........WScript.Echo "Copying File",Files ........newDst=oDst&"\"&Files.Name
........oFSO.CopyFile Files,newDst,True
........WScript.Echo Err.Description
....Next
'Recursive copy, uncomment if needed
' For Each oDir In objFolder.SubFolders
' CopyFiles oDir.Path, oDst
' Next
End SubCopyFiles oUsbDrive,oDestination
[/code]

Thanks for the suggestion Mechanix2Go
and I don't really want a vbscriptSo how about a different question how can I get a batch file to find it's location drive and folder wise and make that a variable that can be used in another command

If you know the fixed drives, let's say c d e f, this might work. It's a little clunky.
::== letter2.bat
@echo off
setLocal EnableDelayedExpansionfor %%a in (g h i j k) do (
dir %%a: > nul
if not errorlevel 1 set letter=%%a:
)
cls
echo it's !letter!
)
::==
=====================================
If at first you don't succeed, you're about average.M2

Well Never mind I found a way to get a variable set to the current directory
all i wish is usb drives would autorun like cd's and so forth, stupid windows
Thread over I guess

"Well Never mind I found a way to get a variable set to the current directory"
LOL There's a built-in var; it's name is: %CD%
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |