Home > Software engineering >  Ask ace to write a batch, thank you!
Ask ace to write a batch, thank you!

Time:11-30

Because of work requirements, the need to move a large number of Excel and Word document to the specified folder, Excel and Word and the name of the folder's name is the same, for example 20160102. Docx file, move to 20160102 _ li Ming can achieve please?

CodePudding user response:

Can write a VBS script is done,

CodePudding user response:

reference 1st floor leonjuno response:
, write a VBS script is done,

Would you help me write the? Thank you,

CodePudding user response:

Vba can also try...

CodePudding user response:

Dir function example
This example USES the Dir function to check some file or directory exists, on Macintosh computers, the default name is "HD" drive, and the path parts separated by a colon instead of backslash, and Microsoft Windows wildcard in Mac can be used as a valid characters appeared in the file name, also can use MacID function to the specified file group,

 Dim MyFile MyPath, MyName 

'return to "WIN. INI" (if the file exists),
MyFile=Dir (" C: \ WINDOWS \ WINDOWS ini ")

'return with specified filename extension, if more than one *. Ini file exists,
'function returns according to the condition of the first to find the file name,
MyFile=Dir (" C: \ WINDOWS \ *. Ini ")

'if a second call Dir function, but without any parameters, the function returns the same directory of the next *.ini file,
MyFile=Dir

'return to find the first implicit *. TXT file,
MyFile=Dir (" *.txt, "vbHidden)

'show C: \ directory name,
MyPath="c: " 'specified path,
MyName=Dir (MyPath, vbDirectory) 'looking for first,
The Do While MyName & lt;> "" 'began circulating,
'to skip the current directory and the upper directory,
If MyName & lt;> ". "And MyName & lt;> ".. "Then
'using a comparison to determine the MyName represents one directory,
If (GetAttr (MyPath & amp; MyName) And vbDirectory)=vbDirectory Then
The Debug. Print MyName 'if it is a directory, to display the name,
End the If
End the If
MyName=Dir 'find next directory,
Loop

FileCopy statements example
This example USES FileCopy statements to copy the file, the example hypothesis SRCFILE to contain a data file,

Dim SourceFile, DestinationFile
SourceFile="SRCFILE" 'specify the source file name,
DestinationFile="DESTFILE" 'specify the destination filename,
FileCopy SourceFile, DestinationFile 'copies the contents of the source files to the destination file,

CodePudding user response:

Does the signature 8 characters to move the same and it is same in the front of the eight letters in the same folder?

CodePudding user response:

reference 5 floor sysdzw reply:
is the signature 8 characters to move the same and it is same in the front of the eight letters in the same folder?
if it is with the following code, deal only with the current default folders and files in the directory:
 Dim fso, objFolders objFolder, rsshell 
The set of fso=CreateObject (" Scripting. FileSystemObject ")
The set rsshell=createobject (" wscript. Shell ")
The Set objFolders=fso. GetFolder (". ")
For Each objFolder objFolders. In SubFolders
Rsshell. Run "CMD/c move" & amp; Left (objFolder. Name, 8) & amp; ". * "& amp; ObjFolder. Name, 0
Next


Processing before


After processing

CodePudding user response:

Bat script directly:
@ echo off
Setlocal EnableDelayedExpansion
For the I/d % % (2016 *) in the do (
: : echo % % ~ ni
The set p=% % ~ ni
The set m=! P: ~ 0, 8!
The echo! m!
For % % a in (! m! Docx) do (echo % % a
Move % % a % % I
)
For % % b (in! m! .xls) do (echo % % b
Move % % % % b I
)
)
Pause


  •  Tags:  
  • VBA
  • Related