Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Moving files & folders

Posted on 2001-09-18
8
Medium Priority
?
198 Views
Last Modified: 2012-05-04
I have the following code in my app:

with FOS do
   begin
   Wnd := Self.Handle;
   wFunc := FO_MOVE;
   pFrom := PChar(UserDrive);
   pTo := PChar(Archive);
   fFlags :=  FOF_ALLOWUNDO;
   end;
SHFileOperation(FOS);

The variable UserDrive points to a network folder (ie. \\server1\users\testuser) and Archive points to a local folder (ie D:\Archive). This procedure fails whatever is in the source folder with the error message "Cannot move I: Cannot find the file specified"

Needless to say, there isn't a file called I. Can anyone help?
0
Comment
Question by:riccohb
[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
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 6489834
dir you try to use it for files instead of folders?

0
 
LVL 8

Accepted Solution

by:
TOndrej earned 340 total points
ID: 6489842
pFrom and pTo must be double-null terminated strings (multiple filenames separated by null character, the whole string terminated by two null characters).

If you want to pass only single file names they must still be terminated by two nulls.
0
 
LVL 7

Expert Comment

by:Motaz
ID: 6489869
I test it using real PCHar and it works:

procedure TForm1.Button1Click(Sender: TObject);
var
  FOS: _SHFILEOPSTRUCTA;
  UserDrive, Archive: PChar;
begin
  UserDrive:= StrAlloc(200);
  Archive:= StrAlloc(200);
  StrCopy(Archive, 'C:\Motaz\Temp');
  StrCopy(UserDrive, 'd:\test');
with FOS do
  begin
  Wnd := Self.Handle;
  wFunc := FO_MOVE;
  pFrom := UserDrive;
  pTo := Archive;
  fFlags :=  FOF_ALLOWUNDO;
  end;
SHFileOperation(FOS);
end;
0
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.

 
LVL 8

Expert Comment

by:TOndrej
ID: 6489925
I read this in MSDN documentation for SHFileOperation... I could have made a mistake, sorry. I'm quite busy at the moment, perhaps I didn't read carefully
0
 

Author Comment

by:riccohb
ID: 6489971
I think it might be something to do with the fact that I'm copying from a network drive specified by \\servername\d$\foldername. If I manually map a drive to this address and run SHFileOperation via the mapped drive letter it works.

I've used Motaz's amended code without using a mapped drive letter, and the error comes back.
0
 
LVL 17

Expert Comment

by:geobul
ID: 6490046
Hi,
There are two possible reasons at least:
1. You do not write the correct path '\\server\path'.
2 You do not have permisions on that folder.

The code works fine with such syntax.

Regards, Geo
0
 

Author Comment

by:riccohb
ID: 6490075
It's definitely the correct path, and I have Domain Admin permissions. Domain Admins have full control of the folder. The code works in so far that it successfully moves all the files and folders from the source to the destination - it's just that once it's done that it looks like it tries to copy one extra file with a nonsense filename (eg |A?).
0
 
LVL 1

Expert Comment

by:pede
ID: 6490530
TOndrej is right about the double termination. Often your string will be followed by zeros because of uninitialized memory, but you really should add that extra #0.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

636 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