I have a Test folder that contains multiple file with two types of filenames as below:
Cycle2605.zip
Cycle2605_P.zip
Cycle2705.zip
Cycle2705_P.zip
What I manage to do is, move all the file from the folder to other server via WinSCP SFTP as shown in the code below.
open sftp://user:password#hostname/ -hostkey="ecdsa-sha2*******"
put D:\Users\AALADELA\Desktop\Test /cygdrive/d/VB_SHARE/astroQA/AFP/in
exit
But how do I move file that in the filename not contain _P to the destination instead of move all file?
open sftp://user:password#hostname/ -hostkey="ecdsa-sha2*******"
if <filename not contain _p> echo put D:\Users\AALADELA\Desktop\Test /cygdrive/d/VB_SHARE/astroQA/AFP/in
exit
You can exclude files matching certain pattern with -filemask switch:
put -filemask=|*_P.zip D:\Users\AALADELA\Desktop\Test /cygdrive/d/VB_SHARE/astroQA/AFP/in
Or you can pick only the files you want, if your file name convention allows, e.g.:
put -filemask=Cycle????.zip D:\Users\AALADELA\Desktop\Test /cygdrive/d/VB_SHARE/astroQA/AFP/in
In this case, it's easier to use a Windows wildcard directly in the source path:
put D:\Users\AALADELA\Desktop\Test\Cycle????.zip /cygdrive/d/VB_SHARE/astroQA/AFP/in/
Related
I am trying to use a simple windows cmd command to move a set of .csv files from one directory to another.
I know that this can be easily achieved through:
MOVE "*.csv" "D:/lorik_home"
The issue comes when I want to only move some specific files with a filename mask, for instance, I want to move all files which are in the .csv extension and start with the name: lorik_files_. I already tried using:
MOVE "lorik_files_*.csv" "D:/lorik_home"
This works when there is only one file of the format: lorik_files_20112233_09_33_33.csv, but when there are two files with the masks such as:
lorik_files_20112233_09_33_33.csv
lorik_files_20112233_10_23_42.csv
I get an error such as:
A duplicate file name exists, or the file cannot be found.
I need a hand for capturing those filename prefix masks, conditioned by .csv extension at the end.
While executing a batch file it only adds files to its own directory, I wanted to make it so that it makes the new TXT file to a specified location
echo You are very good > you.txt
This just makes a text file in the same Dir as the batch file, how would I make it so that it makes the txt file into a specific location
You can easily specify the full path like this:
echo You are very good >"YOUR FULL FILE PATH HERE LIKE C:\MYFOLDER\you.txt"
Hi, I have many zip files located at g:\toto. These zips contain some files. I would like to extract all zip in a same directory (g:\toto\extracted) then rename various files of the zip.
Example 1 :
www_12567.vp.zip : 3 files : alpha.doc, beta.xls, teta.doc
I would like after extraction, files are renamed with the name of the zip
www_12567.vp.alpha.doc, www_12567.vp.beta.xls, www_12567.vp.teta.doc
Example 2 :
www_12.vp.zip : 3 files : al.doc, bea.xls, tta.doc
www_12.vp.al.doc, www_12.vp.bea.xls, www_12.vp.tta.doc
I found this question, but it talks about .txt and the zip contain one file, so, it doesn't work.
Without knowing the contents of the archive you can't know which files to rename, because you are putting them into a directory that may already contain other files.
This, however, would be much easier if there was a dedicated directory to put the files temporarily. Here's how you could use it:
#ECHO OFF
SET "srcdir=G:\toto"
SET "tgtdir=G:\toto\extracted"
SET "tmpdir=G:\toto\extracted-tmp"
FOR %%Z IN ("%srcdir%\*.zip") DO (
unpack "%%Z" with your favourite tool into "%tmpdir%"
FOR %%I IN ("%tmpdir%\*") DO MOVE "%%I" "%tgtdir%\%%~nZ.%%~nxI"
)
Of course, the temporary directory would need to be empty before running the batch file. You could add DEL "%tmpdir%\*" somewhere before the loop to make sure it is.
One other note is, the above assumes that the archives do not contain subdirectories or, at least, that the files are extracted without subdirectories.
UPDATE
If you are using the 7-Zip archiver to work with .zip files, then this is how your extract command might look:
7z e "%%Z" -o"%tmpdir%"
Disclaimer: I'm not an active user of 7-Zip. This is what I used as a reference to come up with the above command:
7-Zip Command-Line Examples
If I make a file foo.exe, and it contains the files bar.bat, baz.bat, and qux.bat, can I call baz.bat from within bar.bat? I mean, if bar.bat is the file that is executed upon execution of foo.exe?
I had done something similar using winrar (instead of iexpress) self extracting archive.
The mechanism is like below:
First it will extract everything to specified folder (or in temporary folder %TEMP%/random_name)
Then it will call initial executable/script or "script to run after extraction". In your case, it's bar.bat.
That executable script can in turn call any other script/executable. (baz.bat in your example)
To be sure, change the file bar.bat to contain below script:
#echo off
cd
explorer .
pause
This will print the directory name, where it has extracted & open the directory with explorer.exe. Then you can verify that your baz.bat is in same directory. Give relative path, if required.
I'm new to Windows batch files, but I'm writing a .bat file that just copies a bunch of files from one place to another maintaining the file directory structure. Using xcopy this is simple but I need to exclude some files from being copied. You can use /exclude and create a text file full of strings that you want to be excluded, but this doesn't just exclude files with the exact names in the text file, it excludes all files whose filenames contain any of the strings in the text file.
What this means is, if I want to exclude any files named 123.txt and put this string in my exclusions text file, if there was a file called 1123.txt anywhere in the source folder or any of its subfolders that would also be excluded.
How can I exclude only files with a specific filename from being copied?
Evening Bill.
Can you add a slash before each file name? That should work
EG
instead of
123.txt
blah.txt
use
\123.txt
\blah.txt
Try creating a temporary folder, xcopying all of the files into that folder, deleting the ones you don't want, then xcopying those to the final destination. Finally, delete the temporary folder and its contents with rd xyzzy /q/s