Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Delete to recycle bin

kompute
Beginner
1,018 Views

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_test

use

ifwin

type

shFileOpStruct

sequence

integer*4

:: hWnd = 0 !long

integer*4

:: wFunc = 0 !long

integer*4

:: pFrom = 0 !string

integer*4

:: pTo = 0 !string

integer*2

:: fFlags = 0 !integer

integer*4

:: fAnyOperationsAborted = 0 !long

integer*4

:: hNameMappings = 0 !long

integer*4

:: lpszProgressTitle = 0 !long

end

type shFileOpStruct

type(shFileOpStruct) SHFileOp

character

*1024 SHFileOpFilename

integer

SHFileOpResult

SHFileOp%wFunc = FO_DELETE

SHFileOpFilename = "tempfile.txt"//

char(0)//char(0)

SHFileOp%pFrom =

loc(SHFileOpFilename)

SHFileOp%fFlags = FOF_ALLOWUNDO

SHFileOpResult = SHFileOperation(SHFileOp)

end

0 Kudos
4 Replies
ggveldkamp2
Novice
1,018 Views
I think you can just use:
TYPE (T_SHFILEOPSTRUCT) :: shFileOpStruct

No need to define the struct yourself.

0 Kudos
kompute
Beginner
1,018 Views

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_test

use

ifwin

type

(T_SHFILEOPSTRUCT) :: SHFileOp

character*1024 SHFileOpFilename

integer

SHFileOpResult

SHFileOp%wFunc = FO_DELETE

SHFileOpFilename = "New *.txt"//

char(0)//char(0)

SHFileOp%pFrom =

loc(SHFileOpFilename)

SHFileOp%fFlags = FOF_ALLOWUNDO

SHFileOpResult = SHFileOperation(SHFileOp)

end

0 Kudos
ggveldkamp2
Novice
1,018 Views
I am not sure, maybe you need to use the FOF_MULTIDESTFILES flag and/or set SHFileOp%pTo=0.

0 Kudos
kompute
Beginner
1,018 Views

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_test

use

ifwin

implicit none

type

(T_WIN32_FIND_DATA):: WFD

type

(T_SHFILEOPSTRUCT):: SHFileOp

character

(LEN=1024) SHFileOpFilename

character

(LEN=MAX_PATH) path

integer

path_len

integer

file_len

integer

SHFileOpResult

integer

hWFD

integer

(SINT) :: ret

logical

bSt, bDummy

file_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 bar

MB_ICONINFORMATION + MB_OK)

! Type flags

write

(*,*) "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

0 Kudos
Reply