Jump to content

User Specific Folders


 Share

Recommended Posts

Does anyone have any idea how you tell the code that the folder title (for example in a shellexecute) is variable - for instance "C:\Users\Adam\My Documents" could also be "C:\Users\Brian's Love Machine\My Documents" and so on.

In MS DOS .bat files the code would be " "%userprofile%"\Documents\*.* "

or similar. any ideas?

Link to comment
Share on other sites

Also, another question that is related to this topic - i am trying to run the app from a memory stick, how can i tell it what letter drive the memory stick is if i had to "SEND("m:/folder/file")"

Thanks

Link to comment
Share on other sites

Does anyone have any idea how you tell the code that the folder title (for example in a shellexecute) is variable - for instance "C:\Users\Adam\My Documents" could also be "C:\Users\Brian's Love Machine\My Documents" and so on.

In MS DOS .bat files the code would be " "%userprofile%"\Documents\*.* "

or similar. any ideas?

@UserProfileDir & "\Documents"

or

@MyDocumentsDir
Link to comment
Share on other sites

Also, another question that is related to this topic - i am trying to run the app from a memory stick, how can i tell it what letter drive the memory stick is if i had to "SEND("m:/folder/file")"

Thanks

If the script is on the removable drive with the app this would work to give you the drive letter...

$myPath = StringLeft(@ScriptDir,3)
Link to comment
Share on other sites

thanks, thats great but how can i use it in the code? where would i put it? if it had

FileCopy("@UserProfileDir & "\Documents"", "$myPath = StringLeft(@ScriptDir,3)")

would that work? im not familiar with any coding language at all (apart from HTML) so i apologise for being a n00b! what do i need to change. I would be interested to know what each part of the code means (what on earth is string left?)

Link to comment
Share on other sites

if im not mistaken (often am) but FileCopy() you cant use variables in the source...

Link to comment
Share on other sites

I suggest you not spread misinformation like this.

:S sorry i guess i was thinking of Fileinstall ()

Filecopy () this is straight from help file

source - The source path of the file(s) to copy. Wildcards are supported.

dest - The destination path of the copied file(s).

flag - [optional] this flag determines whether to overwrite files if they already exist.

Can be a combination of the following:

0 = (default) do not overwrite existing files

1 = overwrite existing files

8 = Create destination directory structure if it doesn't exist (See Remarks).

my bad... :S

Link to comment
Share on other sites

StringLeft = Returns a number of characters from the left-hand side of a string.

FileCopy = Copies one or more files.

@ScriptDir = Directory containing the running script.

@UserProfileDir = Path to current user's Profile folder.

$myPath = StringLeft(@ScriptDir,3)
FileCopy(@UserProfileDir & "\Documents\*.*", $myPath, 9)
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

hmm, thanks thats a bit clearer, - am i right in thinking that the first line in this code defines where the code is run from (lets call it "A" ) and then the second line says "copy this file: "ADAM\documents\*.*" into directory "A""

what does the 9 mean?

ahhhhh also "stringleft = return "3" characters from the left hand side of the directory which would be "D" ":" and "\""

If thats what i think it is GENIUS! is there anything you cant do with this program???

the $mypath is just a label isnt it?

awesome.

Is this Basic or VB or C or what?

thanks alot dude

Link to comment
Share on other sites

also, on this note, and this might be impossible, but is there a way to just copy subfolders and not the stuff in the root directory? also, is there a way of just copying certain types of files, like eg HTML docs or something and leave everything else?

Link to comment
Share on other sites

also, on this note, and this might be impossible, but is there a way to just copy subfolders and not the stuff in the root directory? also, is there a way of just copying certain types of files, like eg HTML docs or something and leave everything else?

Look at the links that I provide you it give you more information about FileCopy(). When you use FileCopy() 9 mean overwrite existing files and create destination directory structure if it doesn't exist. If you want to copy different types of file use the wildcards Ex:(*.htlm, *.doc)
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

sweet ive just discovered wild cards actually!

but what about sub folders?

You can do sub folders only, but you script will be a little bigger. You need to open the help file and search _FileReadToArray() and For...To functions.

1) You need to create a list of sub folders, for that use _FileReadToArray()

2) Then use For...To and combination of FileCopy() to copy the files from the sub folders.

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

can u check if this works?

u might need to add

CopySubFolders(@UserProfileDir & "\Documents\*.*", $myPath, 9)

Func CopySubFolders($SourceFolder,$DestPath )
; If C:\Temp contains a, b, c and destpath is a: Then A: will contain a,b,c

Local $Search,  $File ,  $Attributes ,  $FullPath


;Remove the end \ If specified
If StringRight($SourceFolder,1) = "\" Then $SourceFolder = StringTrimRight($SourceFolder,1)
    
$Search = FileFindFirstFile($SourceFolder & "\*.*")

While 1
            
    If $Search = -1 Then ExitLoop
    
    $File = FileFindNextFile($Search)
    
    If @error Then ExitLoop

    $FullPath = $SourceFolder & "\" & $File
    
    $Attributes = FileGetAttrib($FullPath)
    
    IF @ERROR  Then ExitLoop
    
    If StringInStr($Attributes,"D") Then
        FileCopy($FullPath,$DestPath,9)
    Else
        CopySubFolders($FullPath, $DestPath)
    EndIf

WEnd

FileClose($Search)

EndFunc
Edited by rajeshontheweb
Link to comment
Share on other sites

@MyDocumentsDir ??

Link to comment
Share on other sites

the path to your documents...

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
 Share

  • Recently Browsing   0 members

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