none
How to Copy a file using a universal program directory. RRS feed

  • Question

  • I am trying to copy a file to a directory, and have it so i do not have to do "C:\Users\Andyroo\..."

    I do not want to have to use my user name, but "C:\Users\User\..." doesn't work. any help on copying a file to a directory without using my own username? (i.e, someone else uses the program, and it copies the file to the same directory on their PC)


    ardiezc_quazhulu was here.

    Thursday, July 4, 2013 3:56 AM

Answers

  • Try out environment variables. These are variables that store paths to important folders like C:\, C:\Windows, your home directory C:\Users\Andyroo\... and so on.

    To get a list of all environment variables open the console (with [WIN] + [R], typing "cmd" and hitting [ENTER]) and type

    SET

    and press [ENTER].

    You will see a list of all variables:

    ALLUSERSPROFILE=C:\Documents and Settings\All Users APPDATA=C:\Documents and Settings\florian\Application Data CLIENTNAME=Console CommonProgramFiles=C:\Program Files\Common Files ComSpec=C:\WINDOWS\system32\cmd.exe FP_NO_HOST_CHECK=NO HOMEDRIVE=C: HOMEPATH=\Documents and Settings\florian ProgramFiles=C:\Program Files SystemDrive=C: SystemRoot=C:\WINDOWS TEMP=C:\DOCUME~1\florian\LOCALS~1\Temp TMP=C:\DOCUME~1\florian\LOCALS~1\Temp USERDOMAIN=FLORIANXP USERNAME=florian USERPROFILE=C:\Documents and Settings\florian windir=C:\WINDOWS

    ...

    (the entries may have different names or values as this is taken from a Windows XP machine and I think you work on Windows 7)

    Now if you want to use one of them you have to add a % before and after a variable name so that the operation system knows its a variable and not a path. For example you want to store a file on your desktop. To make the program runnable on different computer with different user names and operation systems (i think most variable names are the same) you use environment variables.

    ' does only work on a Windows 7 machine with the same user name
    File.CopyFile(Program.Directory + "\A.txt", "C:\Users\Andyroo\Desktop\A.txt")
    
    ' works on all Windows systems with any user name
    File.CopyFile(Program.Directory + "\A.txt", "%HOMEPATH%\Desktop\A.txt")

    Thursday, July 4, 2013 5:45 AM

All replies

  • I'll play around with it later, but...
    Could you make a new directory ? like use File.CreateDirectory('c:/Small basic stuff/SBFiles') I'll try it when i get on the laptop. :3

    I am a 12 year old learning how to code using small basic.

    Thursday, July 4, 2013 4:31 AM
  • Actually, I wanted to copy some of the files in my program directory into some already existing system folders on my PC. You can mess with it though ;)

    ardiezc_quazhulu was here.


    Thursday, July 4, 2013 4:40 AM
  • Try out environment variables. These are variables that store paths to important folders like C:\, C:\Windows, your home directory C:\Users\Andyroo\... and so on.

    To get a list of all environment variables open the console (with [WIN] + [R], typing "cmd" and hitting [ENTER]) and type

    SET

    and press [ENTER].

    You will see a list of all variables:

    ALLUSERSPROFILE=C:\Documents and Settings\All Users APPDATA=C:\Documents and Settings\florian\Application Data CLIENTNAME=Console CommonProgramFiles=C:\Program Files\Common Files ComSpec=C:\WINDOWS\system32\cmd.exe FP_NO_HOST_CHECK=NO HOMEDRIVE=C: HOMEPATH=\Documents and Settings\florian ProgramFiles=C:\Program Files SystemDrive=C: SystemRoot=C:\WINDOWS TEMP=C:\DOCUME~1\florian\LOCALS~1\Temp TMP=C:\DOCUME~1\florian\LOCALS~1\Temp USERDOMAIN=FLORIANXP USERNAME=florian USERPROFILE=C:\Documents and Settings\florian windir=C:\WINDOWS

    ...

    (the entries may have different names or values as this is taken from a Windows XP machine and I think you work on Windows 7)

    Now if you want to use one of them you have to add a % before and after a variable name so that the operation system knows its a variable and not a path. For example you want to store a file on your desktop. To make the program runnable on different computer with different user names and operation systems (i think most variable names are the same) you use environment variables.

    ' does only work on a Windows 7 machine with the same user name
    File.CopyFile(Program.Directory + "\A.txt", "C:\Users\Andyroo\Desktop\A.txt")
    
    ' works on all Windows systems with any user name
    File.CopyFile(Program.Directory + "\A.txt", "%HOMEPATH%\Desktop\A.txt")

    Thursday, July 4, 2013 5:45 AM
  • I didn't know you could do that!!! :D

    I am a 12 year old learning how to code using small basic.

    Thursday, July 4, 2013 5:55 AM
  • Omigosh! This actually worked... You are a very talented person, you know that? I owe you, thanks :)


    ardiezc_quazhulu was here.


    Thursday, July 4, 2013 3:31 PM
  • @8bitpony

    neither did i! I thought you could only do paths with % around them in windows 7!


    ardiezc_quazhulu was here.

    Thursday, July 4, 2013 3:37 PM
  • I'm glad I could help :-)
    Thursday, July 4, 2013 4:41 PM