Good day everyone,
I'm fairly new to batch files and have looked up some other batch files based on what I"m looking for but I can't seem to understand how tokens, delims, and variables work.
In any case, here is the batch file i'm trying to come up with and what I need it to do:
1. Remote into an FTP server
2. Go into folder based on changed date
3. Copy file based on certain text in the name and move it to a designated folder
4. Repeat this process for multiple files
Here is a detailed explanation of what I need:
1. Remote into an FTP server (This server is used to hold all our archived files. I will also need to provide username and password)
2. Go into folder based on changed/modified date (I need to pull files from a specific date)
3. Copy file from that folder based on certain text in the name and copyit to a designated folder
(The file will be labeled like this: MOM-00002-XXXXXXXX-XXXXXX-X.jar and I need it to find the specific number after MOM. As the digits go up, the 0's go down, I.E. 00002 > 00022 > 00222 and move it to a folder with the same name as the number)
4. Repeat this process for multiple files ( I need the batch file to pull different files like 00002, 00100, 00350, and move them to their respective folders which is named the same as the number.
I'm getting frustrated as I can't seem to properly understand how tokens, delims, and variables properly work so if you could explain the code as well, it would be very much appreciated.
Thank you in advance.
Batch File to copy items based on text in file name
Moderator: DosItHelp
-
- Posts: 9
- Joined: 25 Aug 2016 23:52
Re: Batch File to copy items based on text in file name
You could use this code to log into a ftp server and execute some commands there. This won't work on sFTP, which nowadays is quite common, so you might wnat to test it (maybe instead of downloading a file using "echo get %myvar%", you might better just perform the dir command using "echo dir").
I'm not sure how you would perform part 2-4 of your task, because you provided to few information:
- What are you doing manually to perform these tasks, and what are the outputs?
- Which characters could be contained in the files?
penpen
I'm not sure how you would perform part 2-4 of your task, because you provided to few information:
- What are you doing manually to perform these tasks, and what are the outputs?
- Which characters could be contained in the files?
penpen
-
- Posts: 9
- Joined: 25 Aug 2016 23:52
Re: Batch File to copy items based on text in file name
Currently, I am just dragging and dropping these files into their appropriate folders although this is extremely tedious and time consuming.
On a daily basis I have 9 folders, that I need to pull 15-20 files for each folder.
Example:
Folder name = 00146
File 1 from date 1/20/2017
File 2 from date 2/15/2017
File 3 from date 3/4/2017
File 1 Needs to go in date changed folder which is named like this: output_20170120230243 when I need to just recognize the date which is the first 8 numbers after the underscore which is 20170120. (Step 2)
The full name for the file 1 would be MOM-00146-20170120_021910 where I only need it to copy by the text 00146 (Step 3)
Then I would need this batch file to repeat for the other dates of files.
On a daily basis I have 9 folders, that I need to pull 15-20 files for each folder.
Example:
Folder name = 00146
File 1 from date 1/20/2017
File 2 from date 2/15/2017
File 3 from date 3/4/2017
File 1 Needs to go in date changed folder which is named like this: output_20170120230243 when I need to just recognize the date which is the first 8 numbers after the underscore which is 20170120. (Step 2)
The full name for the file 1 would be MOM-00146-20170120_021910 where I only need it to copy by the text 00146 (Step 3)
Then I would need this batch file to repeat for the other dates of files.
Re: Batch File to copy items based on text in file name
I think i need more informations (a more detailed description), because i don't know how you decide how to proceed:
- are you really using ftp (so the above script is working), or sFTP (and you have to search for a sFTP command line tool)?
- How do you decide which 9 folders you are processing? (Always the same, or different every day?)
- How do you decide which files you have to process?
- How do you compute the last part of the folder naem to move to ("230243" in "output_20170120230243")?
(- Same for "021910" in "MOM-00146-20170120_021910")
In addition (because i have no access to your ftp server) i need the output of the above ftp example (with "echo dir" instead of "echo get %myvar%"), so i can see the format of the output.
penpen
- are you really using ftp (so the above script is working), or sFTP (and you have to search for a sFTP command line tool)?
- How do you decide which 9 folders you are processing? (Always the same, or different every day?)
- How do you decide which files you have to process?
- How do you compute the last part of the folder naem to move to ("230243" in "output_20170120230243")?
(- Same for "021910" in "MOM-00146-20170120_021910")
In addition (because i have no access to your ftp server) i need the output of the above ftp example (with "echo dir" instead of "echo get %myvar%"), so i can see the format of the output.
penpen