Solved

Rename Files..

Posted on 2001-07-31
11
228 Views
Last Modified: 2010-04-06
Hi,
i wanted to (rename&copy) all files in derectory named
c:\1\ which are all .gif files, to serial names in
c:\2\ .

i mean....
rename c:\1\abc.gif to c:\2\0.gif
rename c:\1\abc4efq.gif to c:\2\1.gif
rename c:\1\abctw4552.gif to c:\2\2.gif


Any fast solution ??
i need to rename 4981 files !!
help pleasd !!
0
Comment
Question by:neostudio
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 6

Expert Comment

by:edey
ID: 6337958
something like

var
 sr : TSearchRec;
 result : integer;
 fileNum : integer;
begin
 fileNum := 0;
 result := findFirst('c:\1\*.gif',faAnyFile,sr);
 while result = 0 do
 begin
  moveFile(pchar('c:\1\'+sr.name),pchar('c:\2\'+intToStr(fileNum)+'.gif');
  result := findNext(sr);
 end;
 findClose(sr);
end;

Note, this is untested "on-the-fly" code, but it _shold_ work

GL
Mike
0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6338066
it is good comment just you forget to

inc(filenum);

also i think  :
copyFile(pchar('c:\1\'+sr.name),pchar('c:\2\'+intToStr(fileNum)+'.gif'),true);

is better becouse he wants to copy not move.

best regards
hamed
0
 
LVL 6

Expert Comment

by:edey
ID: 6338377
Ah, yes, good point(s) hamed.  I can't belive I forgot to increment the fileNumber!

GL
Mike
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6339276
hi edey, neostudio must be carefull for using movefile becouse if he use it instead of copyfile he will not find the original names of the main .gif files in c:\1\ folder. are you agree with me?

best regards
hamed
0
 
LVL 3

Author Comment

by:neostudio
ID: 6340181
Hi guys...

1- please decide who gets the points .
2- small little help is still nededed,
neither copyFile(... or MoveFile(... worker !!
any ideas ??


0
 

Accepted Solution

by:
SMakarenko earned 60 total points
ID: 6340524
try uses next example:




uses ShellApi;

procedure TForm2.Button1Click(Sender: TObject);
var
  FileOp: TSHFileOpStruct;
  DstPos: Integer;
  SrcPos: Integer;
  err, i: Integer;
  s:string;
  ResultStr,ResultStr2: String;
  SearchRec: TSearchRec;
begin
  i:=0;
  if FindFirst('c:\1\*.gif',faAnyFile, SearchRec) = 0 then
  begin
    inc(i);
    ResultStr := 'c:\1\'+SearchRec.Name;
    ResultStr2:= 'c:\2\'+IntToStr(i)+'.gif';
    while FindNext(SearchRec) = 0 do
    begin
      inc(i);
      s := 'c:\1\'+SearchRec.Name;
      ResultStr := Concat(ResultStr, #0, s);
      s := 'c:\2\'+IntToStr(i)+'.gif';
      ResultStr2 := Concat(ResultStr2, #0, s);
    end;
    FindClose(SearchRec);
  end;


  ResultStr := Concat(ResultStr, #0);
  ResultStr2 := Concat(ResultStr2,#0);
  FileOp.Wnd := Application.MainForm.Handle;
  FileOp.wFunc := FO_COPY;
  FileOp.pFrom := PChar(ResultStr);
  FileOp.pTo := PChar(ResultStr2);
  FileOp.fFlags := FOF_NOCONFIRMATION + FOF_NOCONFIRMMKDIR  + FOF_MULTIDESTFILES;
  FileOp.lpszProgressTitle := 'Copy files';
  if SHFileOperation(FileOp) <> 0 then RaiseLastWin32Error;
end;
0
 
LVL 6

Expert Comment

by:edey
ID: 6340530
What happens when you call copy/moveFile?  

GL
Mike
0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6341128
hi edey and neostudio,

there is a grate diference between moveFile and copyFile :

if you call CopyFile all of the file were copied to another directory and give their new name but the original files are stil in the c:\1\ directory without eny change it mean you have numbered file in c:\2\ and stile original files in c:\1\

now if you use movefile all of original files are copied to c:\2\ and there was not eny gif file in c:\1\ folder and you never could understand for example what is the original name of 354.gif ( for example it was hamed.gif at start )

now if original files ( in c:\1\ ) folder is importand for you u must use copyfile but if not you can use moveFile

more clear : copyfile is like <Copy and paste then rename> but movefile is like <Cut and Paste then rename>

best regards
hamed
0
 
LVL 3

Author Comment

by:neostudio
ID: 6342613
Hi...

edey,
The code you posted said copying but did nothing at all, after the copy procedure i made the caption reflect the sr.name to see the proicess if it was going, and it was going from 1 to 503 with no problems, but nothing copied in realtime .
Sorry.

the code posted by SMakarenko worked 100%
your points .



h_mohsenian
O??Co
Thank You
0
 
LVL 1

Expert Comment

by:h_mohsenian
ID: 6345012
sorry , what is the meaning of 'O??Co' ;-)
0
 
LVL 3

Author Comment

by:neostudio
ID: 6345062
;-)
it was SHUKRAN in arabic
but seems like the string was encoded.....

bye
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Copy file in dll not working but working on exe ! 18 93
Run video youtube webbrowse 10 62
oracle global variables 4 68
Tvertscrollbox like a whatsapp layout 5 28
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question