How to move or copy a file between directories that have spa

Just starting out? Need help? Post your questions and find answers here.
elfo116
User
User
Posts: 39
Joined: Sun Oct 12, 2008 9:50 am
Location: CADIZ

How to move or copy a file between directories that have spa

Post by elfo116 »

Hi all ! i'm trying to copy a file from one directory like: C:\Users\PC 1\Desktop\ , but its impossible cause he have a space (PC""1), anyone can help me to solve this ?. Thanks
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: How to move or copy a file between directories that have

Post by Little John »

elfo116 wrote:Hi all ! i'm trying to copy a file from one directory like: C:\Users\PC 1\Desktop\ , but its impossible cause he have a space (PC""1), anyone can help me to solve this ?. Thanks
It depends on what you do in detail :!:
E.g. PB's built-in CopyFile() function does work well also with path names that contain spaces.

In cases like this, it is always a good idea to post the smallest executable code that demonstrates the problem.
elfo116
User
User
Posts: 39
Joined: Sun Oct 12, 2008 9:50 am
Location: CADIZ

Re: How to move or copy a file between directories that have

Post by elfo116 »

Little John wrote:
elfo116 wrote:Hi all ! i'm trying to copy a file from one directory like: C:\Users\PC 1\Desktop\ , but its impossible cause he have a space (PC""1), anyone can help me to solve this ?. Thanks
It depends on what you do in detail :!:
E.g. PB's built-in CopyFile() function does work well also with path names that contain spaces.

In cases like this, it is always a good idea to post the smallest executable code that demonstrates the problem.

Code: Select all

Case 50
        booti$ = OpenFileRequester("", "", "img (*.img)|*.img", 0)
        
If OpenFile(1,booti$)=0:si=0
  MessageRequester("Error","",0)
Else
  si=1:SetMenuTitleText(0,0,"Cargado")
  sep=CountString(booti$,"\")
  fileboot$=StringField(booti$,sep+1,"\")
  dir$=GetCurrentDirectory()
  AddGadgetItem(2,-1,fileboot$)
  DisableGadget(0,0)
  EndIf
   EndSelect
    
Case #PB_Event_Gadget
  Select EventGadget()
      
    Case 0
      
      AddGadgetItem(2, -1,booti$)
      AddGadgetItem(2, -1,dir$)
      AddGadgetItem(2, -1, "==> "+fileboot$)
      AddGadgetItem(2, -1, booti$+" ==> "+dir$+fileboot$)
      
      copiara$=dir$+"unroot\"+fileboot$

  Debug MoveFile_(booti$,copiara$); <----- error copying

Thanks fo your reply
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: How to move or copy a file between directories that have

Post by skywalk »

Better if you provide working code :idea:
You can use RenameFile() instead of api movefile_().
When filenames have spaces, enclose them within double quotes, "c:\try\My long crazy filename.txt".
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: How to move or copy a file between directories that have

Post by Little John »

elfo116 wrote:

Code: Select all

  Debug MoveFile_(booti$,copiara$); <----- error copying
Why don't you use PB's built-in function RenameFile() for moving a file? Like CopyFile(), it works well also with path names that contain spaces.

When using the API function MoveFile_(), you probably have to enclose the path names in double quotes:

Code: Select all

  Debug MoveFile_(#DQUOTE$+booti$+#DQUOTE$, #DQUOTE$+copiara$+#DQUOTE$)
elfo116
User
User
Posts: 39
Joined: Sun Oct 12, 2008 9:50 am
Location: CADIZ

Re: How to move or copy a file between directories that have

Post by elfo116 »

skywalk wrote:Better if you provide working code :idea:
You can use RenameFile() instead of api movefile_().
When filenames have spaces, enclose them within double quotes, "c:\try\My long crazy filename.txt".
Hi !, like this?:

Code: Select all

RenameFile(Chr(34)+booti$+Chr(34),Chr(34)+copiara$+Chr(34)) 
dont work for me :(
elfo116
User
User
Posts: 39
Joined: Sun Oct 12, 2008 9:50 am
Location: CADIZ

Re: How to move or copy a file between directories that have

Post by elfo116 »

Little John wrote:
elfo116 wrote:

Code: Select all

  Debug MoveFile_(booti$,copiara$); <----- error copying
Why don't you use PB's built-in function RenameFile() for moving a file? Like CopyFile(), it works well also with path names that contain spaces.

When using the API function MoveFile_(), you probably have to enclose the path names in double quotes:

Code: Select all

  Debug MoveFile_(#DQUOTE$+booti$+#DQUOTE$, #DQUOTE$+copiara$+#DQUOTE$)
Debug MoveFile_(#DQUOTE$+booti$+#DQUOTE$, #DQUOTE$+copiara$+#DQUOTE$) still returning (0)
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: How to move or copy a file between directories that have

Post by Little John »

Little John wrote:Why don't you use PB's built-in function RenameFile() for moving a file? Like CopyFile(), it works well also with path names that contain spaces.
If you want us to help you, then you should at least answer our questions ...
elfo116
User
User
Posts: 39
Joined: Sun Oct 12, 2008 9:50 am
Location: CADIZ

Re: How to move or copy a file between directories that have

Post by elfo116 »

Little John wrote:
Little John wrote:Why don't you use PB's built-in function RenameFile() for moving a file? Like CopyFile(), it works well also with path names that contain spaces.
If you want us to help you, then you should at least answer our questions ...
Oh sorry, i I did not think that the RenameFile() function served to copy.

I make a output log with de paths obtained from rename function "C:\Users\PC 1\Desktop\TEMP\boot.img" ===> "C:\Users\PC 1\Desktop\MTKR\unroot\newboot.img"
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: How to move or copy a file between directories that have

Post by Little John »

elfo116 wrote:Oh sorry, i I did not think that the RenameFile() function served to copy.
Sometimes you write about copying a file, and sometimes about moving a file. These are two different things.

I told you about both PB's built-in CopyFile() and RenameFile().
You can read the details about both functions in the help.
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: How to move or copy a file between directories that have

Post by #NULL »

Code: Select all

MoveFile_(booti$,copiara$)
no matter if you use RenameFile() or CopyFile() or whatever, but add

Code: Select all

Debug "|"+booti$+"|"
Debug "|"+copiara$+"|"
before and see what you get. Also check if you have write permissions in the directories.
elfo116
User
User
Posts: 39
Joined: Sun Oct 12, 2008 9:50 am
Location: CADIZ

Re: How to move or copy a file between directories that have

Post by elfo116 »

#NULL wrote:

Code: Select all

MoveFile_(booti$,copiara$)
no matter if you use RenameFile() or CopyFile() or whatever, but add

Code: Select all

Debug "|"+booti$+"|"
Debug "|"+copiara$+"|"
before and see what you get. Also check if you have write permissions in the directories.
Hello, thanks for your reply. I get:
|C:\Users\PC 1\Desktop\TEMP\boot.img|
|C:\Users\PC 1\Desktop\MTKR\unroot\newboot.img|
elfo116
User
User
Posts: 39
Joined: Sun Oct 12, 2008 9:50 am
Location: CADIZ

Re: How to move or copy a file between directories that have

Post by elfo116 »

Little John wrote:
elfo116 wrote:Oh sorry, i I did not think that the RenameFile() function served to copy.
Sometimes you write about copying a file, and sometimes about moving a file. These are two different things.

Haha that's because I've tried all the ways I know to move / copy a file

I told you about both PB's built-in CopyFile() and RenameFile().
You can read the details about both functions in the help.

in the "pb.help" there is no help with this, i tryied :lol:
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: How to move or copy a file between directories that have

Post by RASHAD »

As long as you are using Windows API
So search the forum for SHFileOperation_()
It will do the job no matter the filename includes spaces or not
Also no matter the length of the file path
You can Move,Delete,Copy or Rename file(s)
Egypt my love
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: How to move or copy a file between directories that have

Post by Little John »

[color=#0000FF](wrong quoting corrected)[/color] elfo116 wrote:
Little John wrote:
elfo116 wrote:Oh sorry, i I did not think that the RenameFile() function served to copy.
Sometimes you write about copying a file, and sometimes about moving a file. These are two different things.
elfo116 wrote:Haha that's because I've tried all the ways I know to move / copy a file
Yes, that's a good reason for mixing copying and moving up all the time. I'm glad that we have talked about it. :lol: :lol:
elfo116 wrote:
Little John wrote:I told you about both PB's built-in CopyFile() and RenameFile().
You can read the details about both functions in the help.
in the "pb.help" there is no help with this, i tryied :lol:
Oh, it seems that my calendar is broken.
I totally missed that today is April's Fools day. :lol: :lol:
Post Reply