Jump to content

Hi there need help!!!!!!!

 

Using this command "My.Computer.FileSystem.CopyFile("C:\Users\Eddie\Documents\IMG_1008.mp4, "C:\Users\Eddie\Desktop\IMG_1008.mp4" and I want to use this program on another computer with a different Username. What is the command to find the username.

Thanks.

Visual Studio 2.png

Link to comment
https://linustechtips.com/topic/599655-coping-file-with-visual-basic/
Share on other sites

Link to post
Share on other sites

I'd change the title to "Visual Basic". Visual studio is the environment, but visual basic is the language. (You can program in many different languages which have different syntaxes, so copying a file in visual studio doesn't really mean anything.

 

Anyway, what you're looking for is an environment variable. It's something that the operating system (and programs on top of it) uses to find a specific path like the one you're looking for without knowing specific details like the username.

 

http://ss64.com/nt/syntax-variables.html

 

You will be looking for % USERPROFILE %.

 

Use it like this:

CopyFile("%USERPROFILE%\Documents\...

Aragorn (WS): 250D | 6800k | 840 Pro 512GB | Intel 530 480GB  | Asus X99-M WS | 64GB DDR4 | Corsair HX720i | GTX 1070 | Corsair H115i | Philips BDM4350UC 43" 3840x2160 IPS

Gimli (server):  Node 304 | G4560 | ADATA XPG SX8000 128GB | 2x 5TB WD Red | ASROCK H270M-ITX/AC  | 8GB DDR4 | Seasonic 400FL

 Omega (server):                 Fractal Arc Mini R2 | i3 4130 | 500GB Maxtor | 2TB WD Red : Raid 1 | 3TB Seagate Barracuda | 16GB RAM | Seasonic G-450w
Alpha (WS): 900D | 4770k | GTX 780  | 840 Pro 512GB  | GA-Z87X-OC | Corsair RM 850 | 24GB 2400mhz | Samsung S27B970D 2560x1440

                              ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Link to post
Share on other sites

2 hours ago, squirrl said:

CopyFile("%USERPROFILE%\Documents\...

Hard coding a path is brittle. A better way is to use the inbuilt Environment constants:

Environment.SpecialFolder.UserProfile

With Path.Combine (if necessary):

Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Test")

In any event why are you using such a deprecating language?

The single biggest problem in communication is the illusion that it has taken place.

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

×