- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Anyone kind enough to point out what is wrong with the alignment in [shFileOpStruct]? Can't seem to get the program to work.
program
recycle_bin_testuse
ifwintype
shFileOpStructsequence
integer*4
:: hWnd = 0 !longinteger*4
:: wFunc = 0 !longinteger*4
:: pFrom = 0 !stringinteger*4
:: pTo = 0 !stringinteger*2
:: fFlags = 0 !integerinteger*4
:: fAnyOperationsAborted = 0 !longinteger*4
:: hNameMappings = 0 !longinteger*4
:: lpszProgressTitle = 0 !longend
type shFileOpStruct
type(shFileOpStruct) SHFileOp
character
*1024 SHFileOpFilenameinteger
SHFileOpResultSHFileOp%wFunc = FO_DELETE
SHFileOpFilename = "tempfile.txt"//
char(0)//char(0)SHFileOp%pFrom =
loc(SHFileOpFilename)SHFileOp%fFlags = FOF_ALLOWUNDO
SHFileOpResult = SHFileOperation(SHFileOp)
end
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
TYPE (T_SHFILEOPSTRUCT) :: shFileOpStruct
No need to define the struct yourself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks! The program works with a slight bug. I can't find the deleted files in the recycle bin. Any ideas? Is it because I did not specify the directory location?
The code as follows:
program
recycle_bin_testuse
ifwintype
(T_SHFILEOPSTRUCT) :: SHFileOp
character*1024 SHFileOpFilename
integer
SHFileOpResultSHFileOp%wFunc = FO_DELETE
SHFileOpFilename = "New *.txt"//
char(0)//char(0)SHFileOp%pFrom =
loc(SHFileOpFilename)SHFileOp%fFlags = FOF_ALLOWUNDO
SHFileOpResult = SHFileOperation(SHFileOp)
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your help. The problem is that the full path must be specified in order for the undo to work.
The final code is as follows:
program
recycle_bin_testuse
ifwinimplicit none
type
(T_WIN32_FIND_DATA):: WFDtype
(T_SHFILEOPSTRUCT):: SHFileOpcharacter
(LEN=1024) SHFileOpFilenamecharacter
(LEN=MAX_PATH) pathinteger
path_leninteger
file_leninteger
SHFileOpResultinteger
hWFDinteger
(SINT) :: retlogical
bSt, bDummyfile_len = GetModuleFileName (NULL, path,
len(path))path_len =
scan (path, '', back=.true.)ret = MessageBox ( &
GetForegroundWindow(), &
! Handle to window trim(path(1:path_len))//char(0), & ! Text (don't forget C-string if "string" is used)"Full path of executable file"C, &
! Caption for title barMB_ICONINFORMATION + MB_OK)
! Type flagswrite
(*,*) "Path: "//path(1:path_len)bSt = .TRUE.
hWFD = FindFirstFile("New *.txt"//
char(0)//char(0) , WFD)do
while (hWFD /= INVALID_HANDLE_VALUE .AND. bSt)SHFileOp.wFunc = FO_DELETE
SHFileOpFilename =
trim(path(1:path_len))//"New *.txt"//char(0)//char(0)SHFileOp.pFrom =
loc(SHFileOpFilename)SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION + FOF_MULTIDESTFILES
SHFileOpResult = SHFileOperation(SHFileOp)
bSt = FindNextFile(hWFD, WFD)
end do
! illustrate alternative coding method
bSt = .TRUE.
hWFD = FindFirstF ile("Old *.txt"//
char(0)//char(0) , WFD)do
while (hWFD /= INVALID_HANDLE_VALUE .AND. bSt)SHFileOp%wFunc = FO_DELETE
SHFileOpFilename =
trim(path(1:path_len))//"Old *.txt"//char(0)//char(0)SHFileOp%pFrom =
loc(SHFileOpFilename)SHFileOp%fFlags = FOF_ALLOWUNDO.or.FOF_NOCONFIRMATION.or.FOF_MULTIDESTFILES
SHFileOpResult = SHFileOperation(SHFileOp)
bSt = FindNextFile(hWFD, WFD)
end do
end

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page