Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

Automatic Cut and Paste in Common Dialog area

Hi,

I was wondering if a Common Dialog can be used to perform the following task:

1) 'Step one' button is clicked on main interface
2) Calls a Common Dialog box that defaults to the original image folder:
a) User selects the file(s) that they want to cut (using ctrl-A once a folder is opened, or shift select)
b) User clicks 'Open' button after making selection, thus cutting and pasting all files selected into the C:\My Documents\My Pictures folder
c) This closes the Common Dialog
3) On the main interface, user clicks the "Step 2" button, which then converts all images in C:\My Documents\My Pictures from .bmp format into a multipage tiff (I already have all of this worked out)
4) User exits the program

This could be modified to have three steps:
1). Open
2). Save
3). Process

Source code and additional information can be found at this messageboard:
http://forums.devx.com/showthread.php?p=424594#post424594

I've been doing research and have found all sorts of possible solutions (none of which have been successful for me), including:

API - SHFILEOPSTRUCT
GetData
FileCopy
Recursion
The My.Computer.FileSystem.CopyDirectory command
private static void CopyDirectory(string sourceDirectory, string destinationDirectory)
GDI+ API
etc.

At this point I'm lost on what to do!  Any help would be greatly appreciated.

Thanks!

Chris
0
cmjwebservices
Asked:
cmjwebservices
1 Solution
 
PreeceCommented:
What language are you wanting to do this in.  Your examples seem to hint at some variant of C...
0
 
cmjwebservicesAuthor Commented:
Sorry, left out some of the most important information:

Visual Basic 6.0 sp6
Windows XP sp2
0
 
rettiseertCommented:
Hi, this is a way to do it, add this at the beginning of your form code outside any function or sub:

''''''''''''''''''''''''''''''''''''''''''''''''''
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Private Type SHFILEOPSTRUCT
    hWnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAborted As Boolean
    hNameMaps As Long
    sProgress As String
End Type
''''''''''''''''''''''''''''''''''''''''''''''''''

Now modify your sub this way:


''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub cmdMoveImages_Click()
   
    Dim strOpenFile As String
    On Error GoTo ErrHandler
    ' Set Cancel to True
    CommonDlg1.CancelError = True
    ' Set flags (includes multiple file select)
    CommonDlg1.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly + cdlOFNAllowMultiselect + cdlOFNExplorer Or cdlOFNNoLongNames
    ' Set filters
    ' Account for file extension
    CommonDlg1.Filter = "All Files (*.*)|*.*|Bitmaps (*.bmp)|*.bmp|Jpegs (*.jpg)|*.jpg|Gifs (*.gif)|*.gif"
    ' Change the window title
    CommonDlg1.DialogTitle = "Select Images for Processing"
    ' Set the default folder
    CommonDlg1.InitDir = "C:\Program Files\Sieratechnical\"
    ' Specify default filter
    CommonDlg1.FilterIndex = 2
    CommonDlg1.ShowOpen
   
    strOpenFile = CommonDlg1.FileName
   
   
   
    Dim FilesToMove() As String
    Dim I As Long
    Dim FileOp As SHFILEOPSTRUCT
   
    Const FO_MOVE = &H1
   
    FilesToMove = Split(strOpenFile, Chr(0)) 'Get all the selected files in an array
    FileOp.hWnd = 0
    FileOp.wFunc = FO_MOVE  'We are going to move files
   
   'Prepare the file names we are going to move
    For I = 1 To UBound(FilesToMove)  
        FileOp.pFrom = FileOp.pFrom + FilesToMove(0) + "\" + FilesToMove(I) + Chr(0)
    Next
    FileOp.pFrom = FileOp.pFrom + Chr(0) + Chr(0)

    'Prepare destination folder
    FileOp.pTo = "C:\My Documents\My Pictures"
   
    'Move the files
    SHFileOperation FileOp
   
ErrHandler:
    ' User pressed the Cancel button

End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
cmjwebservicesAuthor Commented:
I'm getting the following:

Compile error:

Ambiguous name detected: SHFileOperation

Any ideas?
0
 
cmjwebservicesAuthor Commented:
Ok, I think I found the source of the error posted above...However, when running the program, I now get:

"Can't find project or library"

and the debugger points to this line:

FilesToMove = Split(strOpenFile, Chr(0)) 'Get all the selected files in an array

particularly the "Chr" of the above...
0
 
cmjwebservicesAuthor Commented:
The problem could possibly be:

MethodInfos for functions in mscorlib.dll

is only present in .net (unless there is a component or library I need to load in addition to what I have already)...
0
 
andrewbleakleyCommented:
Once you have the individual filenames (using cmjwebservices code FilesToMove = Split(strOpenFile, Chr(0)))

use the File Object and the File.Copy method to copy the files from the present path to the My Pictures Folder

Basically for each file in selected_file
Dim oFile as File
Set oFile = New File
oFile.Path = "Selected File"
oFile.Copy "C:\My Documemts\my Pictures\", True
Set oFile = Nothing

Add a reference to Microsoft Scripting Runtime to get access to the File object. Sorry my VB is crude it has been a while
0
 
rettiseertCommented:
Cant use Chr?
mmm... I haven't seen this before

You don't need any library to use Chr, it has been there since the old days of qbasic, try using Chr$(0) instead of Chr(0)
0
 
rettiseertCommented:
or replace every Chr(0) with vbNullChar, that must fix the proble if Chr is the cause...
0
 
cmjwebservicesAuthor Commented:
Thanks rettiseert!

Actually, I created a new project and the code you posted worked fine...So, from there I thought that maybe I needed to install VB.net (which I, coincidentally had).  But, before I finished installing it, I deleted multiple modules from the code (which did no good), and changed this line to reflect the declaration

'Move the files
    SHFileOperation FileOp

to

SHFileOperationA FileOp ' (i.e., the alias)

AND

commented out the following declaration I had in the header of the code:

' Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

and the conflict was solved!!

Thanks a lot for your help!  It was a good learning experience going through all of this, but I'm glad I have it finished.

Regards,

CJ
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now