Page 1 of 2

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

Posted: Thu Mar 21, 2019 4:17 pm
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

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

Posted: Thu Mar 21, 2019 4:44 pm
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.

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

Posted: Thu Mar 21, 2019 5:39 pm
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

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

Posted: Thu Mar 21, 2019 6:07 pm
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".

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

Posted: Thu Mar 21, 2019 6:14 pm
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$)

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

Posted: Thu Mar 21, 2019 6:26 pm
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 :(

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

Posted: Thu Mar 21, 2019 6:28 pm
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)

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

Posted: Thu Mar 21, 2019 6:35 pm
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 ...

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

Posted: Thu Mar 21, 2019 6:43 pm
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"

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

Posted: Thu Mar 21, 2019 6:52 pm
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.

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

Posted: Thu Mar 21, 2019 6:56 pm
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.

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

Posted: Thu Mar 21, 2019 7:17 pm
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|

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

Posted: Thu Mar 21, 2019 7:21 pm
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:

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

Posted: Thu Mar 21, 2019 7:34 pm
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)

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

Posted: Thu Mar 21, 2019 11:47 pm
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: