batch script can't copy fine in a folder containing a space - batch-file

I have the following batch code
copy H:\test\Folder\sample.ini H:\test\sample.ini
Pretty straight forward. However, it doesn't work if I modify the code to look in "New Folder" instead of "Folder".
In other words, I get a "file cannot be found error" if the directory structure contains a space. How can I resolve this?

it Doesn't work because there is a space in your Directory name(i.e New Folder) and it confuses windows interpreter,so all you have to do is add "" around your path.the following code should do your job:
COPY /Y "H:\test\New folder\sample.ini" "H:\test\sample.ini"

Related

How to copy file to another folder using cmd?

Currently I'm using the code below to try and make a batch file to automatically copy the file to my 'test location' folder.
xcopy "C:\Users\MyComputer\Desktop\Excel.xlsx" "C:\Users\MyComputer\Desktop\test location\Excel.xlsx"
However it doesn't seem to be working. I picked up the code online and made my own modifications. Am I missing something?
Double-check the name of your destination folder to make sure you aren't missing an underscore or something. Then try removing \Excel.xlsx from the end of your destination specification and see if it works:
xcopy "C:\Users\MyComputer\Desktop\Excel.xlsx" "C:\Users\MyComputer\Desktop\test location"

Copy an image and save as new name in different folder

I have an image. Say its
Cutedoggo.png which is sitting on my desktop
I would like to copy it over, rename it , and save it to a new destination. Let's say I want to rename it to Dog1.png in the c:/doggo folder I've made
I tried in windows command prompt (while inside the directory of original file)
copy CuteDoggo.png Dog1.png c:/doggo but it didn't work. Error message
error: the syntax of name is incorrect
how would I accomplish this using command prompt?
copy "CuteDoggo.png" "c:\doggo\Dog1.png"
also this works as well: (simplified)
copy CuteDoggo.png c:\doggo\Dog1.png EDIT this will not work if there's a space in folder.
courtesy of stephan

Copy Files and pasting them in a batch file

So what i'm trying to do is get a selected file from File explorer, and copy it then paste it into a new folder via a batch file upon clicking it....is there a way?
One way I can think about you doing that is by creating a some sort of data base thing
For Example
#echo off
:fileSelect
echo Which folder do you want?
set /p folderName=
goto %folderName%
You can do it that way. Then you will have to manually put in the locations the files like so
:"Files Name here"
copy C:\"Files location" C:\"Designated location to paste file"
goto fileSelect
That's one simple way of doing it. If that's not exactly what you want or if its unclear let me know and I will attempt to help you find another way to do it.

using the dir command writing a batch proccess

Im writing a batch file for work. basically my command right now navigates to a file path, then prints out the contents of the folder with the dir command.
Without giving the specifics away of what i am trying to print out here is the code im using
CD C:\Some folder\some folder2\some folder 3\some folder 4
DIR
now in "some folder4" there are 3 files. If i use the code
CD C:\Some folder\some folder2\some folder 3
DIR
It prints out fine that there is a folder "some folder4" in "Some Folder3", but as soon as i change the directory into the "some folder4" folder it says file not found instead of showing me the 3 files that are in it.
Any advice as to what would be causing this
I think we need more specifics of what you're doing here (you're going to have to give away a bit more), but one thing you should definitely look at is the for /d command instead of DIR.
You know you can use a filespec with the DIR (or for) command right? Changing the directory isn't really the best choice - especially since drive and relative paths are assumptions. [cd h:\test\ doesn't switch drive if you're on c:\, but dir h:\test\ will work no matter what drive you're on]
If your folders have spaces in them, it could be you need to escape the folder name with quotes (cd "some folder4").

XCOPY exclude list ignored after first exclusion

I have a batch file I've created which uses xcopy to copy a dir, and child dirs, and merge them into one file. (ie. all my modulised development css stylesheets merged into one production stylesheet).
Everything is good, apart from the fact that when I reference the excludelist.txt, it only excludes the first line, and not the subsequent files I want excluded.
Anyone fancy a crack at this? You'd be most helpful.
Here's the code:
XCOPY C:\xampp\htdocs\PROJECT\css\*.* C:\temp /S /I /Y /EXCLUDE:C:\xampp\htdocs\PROJECT\exclude.txt
...and inside my exclude.txt is...
1.css
2.css
3.css
4.css
5.css
///// I know the code works (to an extent) because it is infact excluding file 1.css -- just not the ones below it. Am I right to put each exclusion on a new line?
I use the following,
xcopy "C:\users\dad\*.*" dad /s /d <yesnoyesno /EXCLUDE:excluexclu 1>cop.txt 2>err.txt
as somewhere on the web I saw a note to the effect that the /Y switch could not be used directly with an exclude file.
What I wanted to point out here, was the useful output files 1 & 2, which detail the success & failure issues.
Mine shows only success.
The short answer: Create a new text file, type the entries and save the file.
The longer explanation: I ran into this very issue on a Windows 2008 server today. I tried all kinds of things to get it to work. Forced notepad to save the file as ANSI, Unicode and UTF-8 but all of them had the same problem. Finally I started thinking about the fact that I put the file on the server via FTP and it's quite likely that FTP tweaked the file format. I created a new text file on the server, typed all the same entries in the new file and now it works.
I had a similar problem. I was trying to exclude all files with a certain extension in the root folder and any sub-folders and it didn't work. The reason was I was putting *.pdb instead of just .pdb. The newline/carriage return thing was a total red herring for me.
So my file just looked like:
.pdb
.obj
.vb
.cs
You seem to be using xcopy correctly - each exclusion file (or match depending on wildcards) should be on a new line within the file. So far I've been unable to reproduce the behaviour you're experiencing.
Is the exclude.txt listing you've given above a test file, or are they the actual css names?
What are the names of the other files that your batch file is supposed to copy?
Edit:
That the xcopy is failing to exclude further files after a single match is giving me most pause. I thought it might be to do with the type of carriage-return that was used in the exclude file, but xcopy handles unix-style carriage-returns just fine.
Can you re-verify that the correct exclude file is being used?
Try forcing it to save with ANSI encoding on your text editor.
I was having a similar issue and that did it.

Resources