Issues Using Wildcard in Batch-script to Copy a Variable File Name - batch-file

My Process:
For version control, all my files are named with the format "fileName_v#.#"
I keep a folder called 'Live Environment', and as a new version is rolled out, the current file (ex. fileName_v1.0) is removed from 'Live Environment' folder, and the new version (ex. fileName_v2.0) is moved into 'Live Environment'.
My batch script is used to keep all users on the most current version. It works perfect, except with every version I need to go back and update the hard-coded file name in my script to the new file name.
I would like to use a wildcard to search this folder for whatever file is in the 'Live Environment' folder, and then perform the copy function.
Current Code:
::Sets the default install location as the user's desktop
set "DestinationFolder=%userprofile%\desktop"
::Copies and saves file to the user's Desktop
copy /-y "\\myUNCPath\Live Environment\fileName_v*.accdb" "%DestinationFolder%\copiedFile.accdb"
My Issue:
I've hardcoded the "fileName_v#.#.accdb" in for each version so far, and the code executes perfectly. The second I remove the hardcoded file version and add the "*" wildcard, the code errors. The copy function still runs, but simply creates an empty .accdb file on the users desktop, which when used gives the error:
"Unrecognized database format"
At this point I'm overthinking this and making it harder than it needs to be. A set of fresh eyes on the issue would be helpful. Any help would be greatly appreciated!

#aschipfl - that worked! Thanks for the comment.
Simply adding "/b" to the copy line fixed the issue.
copy /-y /b
(For more details see the aschipfl's comment posted below the question).

Related

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

Word default folder is different when started programmatically

We have a 2 step process that collects all filenames from a folder into a Word document for use elsewhere.
The original process was to run an old DOS batchfile that collected the filenames into a DOS .txt. Then we launched a Word .docx with a macro that imported the .txt and massaged the formatting. After visual inspection we hit ‘Save’ and that was it.
I had the bright idea that a step could be taken out by launching Word directly from the batch, so I inserted the line: start winword filename. This works great except that the default location that Word wants to save in is now my Templates folder. Running it the old way still works perfectly.
The question is: why is the default location changed by launching Word programmatically and how can it be forced back to the correct location?
Thanks
you can use:
start /D C:\path\to\folder "" winword.exe
this program starts winword.exe and save all files to C:\path\to\folder
ill assume that winword.exe is in the current directory.
for help with the start command : http://ss64.com/nt/start.htm
I investigated the start command, but never did figure out why it operated differently. The eventual solution was to include the Save action in the macro. I still don't know why we didn't have to do that before, but it works now so we're declaring success and moving on.

xcopy to "%AppData%\Roaming\Microsoft\Excel\XLSTART\" stated copied yet nothing is there

I'm trying to write a small bat script to put on my teams desktops and allow them to update their personal macro file with mine when ever I push out an update or have created new tools.
I have the following
xcopy "O:\abc Supply chain\Supply Chain Team\David Peters\Excel\Macro File" "%AppData%\Roaming\Microsoft\Excel\XLSTART\" /y
under CMD is says 1 files copied yet there isn't anything in the XLSTART folder.
can you pleased tell me what I'm doing wrong
many thanks
Not sure about your configuration, but for me the Roaming folder is already included in the value of the %AppData% variable.
"%AppData%\Roaming\Microsoft\Excel\XLSTART\"
^......^
So, probably you should use "%AppData%\Microsoft\Excel\XLSTART\"

mercurial .hgignore - won't ignore files

I'm trying to ignore a file in my project with .hgignore, and just can't figure it out. The file is located in app/views/patterns/_changes.erb (relative to the root of the project, where .hgignore is), and nothing I try seem to work:
#.hgignore
syntax: glob
app/views/patterns/_changes.erb
*changes.erb
public/files/* # this works
I read the .hgignore doesn't distinguish between folders and files, but can't really make it happen. Any clue? thanks.
If you just put:
_changes.erb
as an entry, that should work. It will ignore that file name, regardless of location. Note that if the file is already in the repository, it won't REMOVE it... it just won't prompt you to add it next time it sees a file with that name.
As a side note, if you want to remove a file from version control, use the command:
hg forget _changes.erb
(Note that this will remove the file from the current revision onwards. The file will always remain in past changesets -- i.e. it's not a total purge of the file.)

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