Jump to content

Wildcard in FileCopy destination


Recommended Posts

I'm sure there is a simple explanation that I'm just not seeing. I need to include in my script a file copy to a destination path which includes several variable characters. That is, the last part of the path contains characters which vary from user to user.

The following did not work successfully:

$szFile = "c:\prefs2.txt"

$workingdir = "C:\Documents and Settings\jjp\Application Data\Thunderbird\profiles\*.default\"

FileCopy($szFile, $workingdir)

The wildcard represents the part of the directory which changes from user to user.

Please help.

Thanks in advance.

Link to comment
Share on other sites

Try this;

#Include <File.au3>

$szFile = "c:\prefs2.txt"
$workingdir = "C:\Documents and Settings\jjp\Application Data\Thunderbird\profiles\"

$FolderList=_FileListToArray($workingdir,"*.default",2)
If (Not IsArray($FolderList)) and (@Error=1) Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
for $i = 1 to $FolderList[0]
    $folder = $workingdir & $FolderList[$i]
    FileCopy($szFile, $folder)
Next

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

Whats the .default for?

I'm not very experienced with autoit, but i'm pretty sure its not supposed to look like that. Whats the meaning of having the .default there?

The ".default" is the part of the directory name that is constant.

Link to comment
Share on other sites

You would have to have a way to check which user unless your trying to copy it into all the users folder, in which case you could use FileFindFirstFile and FileFindNextFile I beleive.

The directory I listed is actually a single directory on each workstation. I want to copy the file into this directory (I'm running from a login script) except I only know the last portion of the directory name...the ".default" portion.
Link to comment
Share on other sites

Perhaps you could show a few examples of what end result you are looking for, are you saying:

c:\prefs2.txt > C:\Documents and Settings\jjp\Application Data\Thunderbird\profiles\prefs2.default

c:\prefs1.txt > C:\Documents and Settings\jjp\Application Data\Thunderbird\profiles\prefs1.default

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

Perhaps you could show a few examples of what end result you are looking for, are you saying:

c:\prefs2.txt > C:\Documents and Settings\jjp\Application Data\Thunderbird\profiles\prefs2.default

c:\prefs1.txt > C:\Documents and Settings\jjp\Application Data\Thunderbird\profiles\prefs1.default

Sure:

c:\prefs.txt > C:\Documents and Settings\jjp\Application Data\Thunderbird\profiles\xpfcn5m2.default\prefs.txt

The "xpfcn5m2" is the portion that varies and is the part I was representing with a wildcard character.

Thanks again for helping me figure this out.

Link to comment
Share on other sites

Try this;

#Include <File.au3>

$szFile = "c:\prefs2.txt"
$workingdir = "C:\Documents and Settings\jjp\Application Data\Thunderbird\profiles\"

$FolderList=_FileListToArray($workingdir,"*.default",2)
If (Not IsArray($FolderList)) and (@Error=1) Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
for $i = 1 to $FolderList[0]
    $folder = $workingdir & $FolderList[$i]
    FileCopy($szFile, $folder)
Next
Am I wrong or is the _FileListToArray not a defined AutoIt3 function? I can't seem to find reference to it.
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...