Jump to content
Sign in to follow this  
AJJ

User Specific Folders

Recommended Posts

AJJ

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?

Share this post


Link to post
Share on other sites
AJJ

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

Share this post


Link to post
Share on other sites
erik7426

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

Share this post


Link to post
Share on other sites
erik7426

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)

Share this post


Link to post
Share on other sites
AJJ

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?)

Share this post


Link to post
Share on other sites
CodyBarrett

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

Share this post


Link to post
Share on other sites
Valik

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

I suggest you not spread misinformation like this.

Share this post


Link to post
Share on other sites
CodyBarrett

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

Share this post


Link to post
Share on other sites
AJJ

does anyone have any ideas what i need to do to put this into my code, im not really sure?

Share this post


Link to post
Share on other sites
Danny35d

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

Share this post


Link to post
Share on other sites
AJJ

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

Share this post


Link to post
Share on other sites
AJJ

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?

Share this post


Link to post
Share on other sites
Danny35d

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

Share this post


Link to post
Share on other sites
AJJ

sweet ive just discovered wild cards actually!

but what about sub folders?

Share this post


Link to post
Share on other sites
Danny35d

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

Share this post


Link to post
Share on other sites
rajeshontheweb

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

Share this post


Link to post
Share on other sites
CodyBarrett

@MyDocumentsDir ??

Share this post


Link to post
Share on other sites
AJJ

erm what?

Share this post


Link to post
Share on other sites
CodyBarrett

the path to your documents...

Share this post


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
Sign in to follow this  

×