June 16, 2024, 12:37:03 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Strange problem with USING

Started by billhsln, May 15, 2011, 10:37:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

It seems that the first time I run this program, it starts renaming files with 1000, but the second time it seems to work the way I expect (Pic_001.jpg, Pic_002.jpg, etc).  Any idea what I may be doing wrong?

' Rename_Multi_JPG's.IWB

DECLARE IMPORT,SHBrowseForFolder(param1:uint),int
DECLARE IMPORT,SHGetPathFromIDList(param1:uint, param2:uint),int
DECLARE IMPORT,CoTaskMemFree(param1:int),int
DECLARE IMPORT,RtlZeroMemory(dat:uint,length:int),int
DECLARE IMPORT,SendMessageA(hWnd:uint, message:uint, wParam:int, lparam:uint),uint
DECLARE IMPORT, _MoveFile alias MoveFileA(lpExistingFileName as STRING,lpNewFileName as STRING),INT
DECLARE FolderRequest(hWnd:uint, title:pointer, dir:pointer, initial:pointer, flags:uint),int
DECLARE GetFilesDIR(Path:string)
DECLARE BrowseFolderCallback(hWnd:uint, uMsg:uint, lParam:uint, lpData:uint),int
DECLARE rename(FileName:string,NewfileName:string),int

TYPE BROWSEINFO
UINT hOwner
UINT pidlRoot
POINTER pszDisplayName
POINTER lpszTitle
UINT ulFlags
UINT lpfn
UINT lParam
UINT iImage
ENDTYPE

CONST WM_USER = 0x400
CONST BFFM_SETSELECTION = WM_USER + 102
CONST BFFM_INITIALIZED = 1
CONST BFFM_VALIDATEFAILED = 3
CONST BIF_RETURNFSANCESTORS = 8
CONST BIF_RETURNONLYFSDIRS = 1
CONST BIF_NEWDIALOGSTYLE = 0x40
CONST BIF_DONTGOBELOWDOMAIN = 2

ISTRING dir[260], Sdir[260]
OPENCONSOLE
'Sdir = GetStartPath
Sdir = "C:\\Users\\BillH\\Documents\\NTSCA\\showphotos"
IF FolderRequest(0, "Choose folder", dir, Sdir, 0x441)
GetFilesDIR(dir)
ENDIF
WAITCON
CLOSECONSOLE
END

'----------------------------------------------------------------------------------------
SUB FolderRequest(hWnd:uint, title:pointer, dir:pointer, initial:pointer, flags:uint),int
'----------------------------------------------------------------------------------------
INT r = FALSE
ISTRING buffer[260]
UINT item_list
BROWSEINFO bi
RtlZeroMemory(&bi, LEN(bi))
bi.hOwner = hWnd
bi.lpszTitle = title
bi.ulFlags = flags
IF flags = 0 THEN bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | BIF_DONTGOBELOWDOMAIN
bi.lpfn = &BrowseFolderCallback
bi.lParam = initial
' Display the browser.
item_list = SHBrowseForFolder(&bi)
IF item_list
IF SHGetPathFromIDList(item_list, &buffer)
IF MID$(buffer,LEN(buffer),1) <> "\\"
#<STRING>dir = buffer + "\\"
ELSE
#<STRING>dir = buffer
ENDIF
r = TRUE
ENDIF
CoTaskMemFree(item_list)
ENDIF
RETURN r
ENDSUB

'---------------------------------------------------------------------------
SUB BrowseFolderCallback(hWnd:uint, uMsg:uint, lParam:uint, lpData:uint),int
'---------------------------------------------------------------------------
SELECT uMsg
CASE BFFM_INITIALIZED
SendMessageA( hWnd, BFFM_SETSELECTION, TRUE, lpData )
CASE BFFM_VALIDATEFAILED
RETURN 1
ENDSELECT
RETURN 0
ENDSUB

'---------------------------
SUB GetFilesDIR(Path:string)
'---------------------------
DEF Npath, Cpath, Opath:string
DEF dir, attrib, cntr:int

cntr = 0
Npath = Path + "*.jpg"
dir = FINDOPEN(Npath)
IF (dir)
DO
Cpath = FINDNEXT(dir,attrib)
IF Cpath <> ""
IF (attrib & @file_directory)
Opath = ""
ELSE
cntr++
Opath = "Pic_" + USING("0###",cntr) + ".jpg"
IF RENAME(Path + Cpath, Path + Opath)
PRINT Cpath, " Renamed to ", Opath
ELSE
PRINT Cpath, " NOT Renamed to ", Opath
ENDIF
ENDIF
ENDIF
UNTIL Cpath = ""
FINDCLOSE dir
ENDIF

RETURN
ENDSUB

'-------------------------------------------------
SUB rename(FileName:string,NewfileName:string),int
'-------------------------------------------------
res = _MoveFile(FileName,NewfileName)
RETURN res
ENDSUB


Thanks,
Bill
When all else fails, get a bigger hammer.

whitenite1

Bill..
 I compiled it, and it worked correctly the first time I ran it. Pic_001.jpg thru Pic_012.jpg It may be hard for someone to figure out why it doesn't work right on your computer, when it's working perfectly on theirs.
 Good luck...

whitenite1

LarryMc

I looked at your code and don't see anything wrong with it.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

I have found that it seems my version of Windows 7 Pro might be the problem.  Seems that if I table up the file names, in a string array, and then change them after I find all of them, it works ok.  Seems that when I rename the file in the read files logic, it takes the renamed file as a new file and then reads it again and keeps doing that until it is over 1000.  Since I changed it to store the info in a string array and rename after, it works ok now.

Bill
When all else fails, get a bigger hammer.