Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Rename Files..

Posted on 2001-07-31
11
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 240 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 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